0

Consider the following hierarchy of classes:

struct B {
    int i;
};

struct D : B {
    int j;
};

B is aggregate class, but D is not (because of base class existance). Is there a way to initialize array of D's like aggregate (i.e. without having user writen constructors)?

B b[] = {1, 2, 3}; // ok
D d[] = { ????? }; // is it possible?
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
  • It's not quite a duplicate: the linked question asks only about the 'why', whereas here it is about the workaround. – davidhigh Nov 23 '15 at 08:22
  • @davidhigh I think it's diplicate though. Because says it is not possible without user defined ctor (`the compiler will look for an appropriate constructor.`). Thank you for your attention. – αλεχολυτ Nov 23 '15 at 08:30

0 Answers0