dimanche 29 novembre 2015

Aggregate initialization of an array of objects with `new` which compiler is right?

Supposedly, I have the following class:

class Foo { 
  int i;
public:
  Foo(int const i_) : i(i_) {}
  int geti() const { return i; }
};

and the following piece of code in main:

Foo* centroids = new Foo[5]{{1}, {2}, {3}, {4}, {5}};

GCC compiles and runs it with no problem demo, while CLANG gives a compile error demo

error: no matching constructor for initialization of 'Foo'

So which compiler is right?

Aucun commentaire:

Enregistrer un commentaire