Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initializer list constructor error with CRTP

I'm wetting my feet with C++11 and am really confused why this doesn't work:

template <class T>
struct A {
  size_t size() const { return sizeof(T); }
};

struct B : A<B> {
  int x;
  int y;
};

B var {1, 5};

I'm using gcc 4.8.2 and get an error saying:

no matching function for call to 'B(<brace-enclosed initializer list>)'

It works just fine when I don't derive from A, so does the derivation somehow change the POD-ness of my struct B?

like image 851
eddi Avatar asked May 06 '15 19:05

eddi


1 Answers

Aggregate-initialization requires your type to be an aggregate. An aggregate cannot have base classes:

An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).

like image 132
David G Avatar answered Oct 13 '22 13:10

David G