Wednesday, 11 September 2013

Braces (without constructor) initialization of a derived class

Braces (without constructor) initialization of a derived class

struct base {
};
//struct derived { // <--- this one works
struct derived : public base { // <--- but this one doesn't
double x;
};
main () {
derived d{0.5};
return 0;
}
What is the way to initialize derived using braces, meaning without
explicitly writing a constructor?

No comments:

Post a Comment