Your code is equivalent to this:
struct Foo { Foo(int){}
The problem is that in rhs Foo* pFoo = new Foo[10]; you allocate memory , and also create 10 Foo objects . The compiler does not know how to do the latter (creating objects), since you do not provide a default constructor. For this code to work as it is, you need to specify all arguments for the non-default ctor of each object, for example:
Foo* pFoo = new Foo[10]{1,2,3,4,5,6,7,8,9,0};
A better alternative is to use std::vector . If you are wondering why the latter works without the need for objects that do not have a default constructor, this is because it uses the new location and initializes the elements on demand.
Here you can see how to do this with the new placement.
EDIT
The code
Foo* pFoo = new Foo[10]{1,2,3,4,5,6,7,8,9,0};
compiles in gcc, but clang cannot compile it (with the -std=c++11 flag). The next question is here .
vsoftco
source share