3 ms·
The example looks like this: class A { protected: A() {} } class B : public A {} B x; //ok B y{}; //not ok, can't access A::A() Would the T
by tsimionescu 3y ago
The example looks like this:
class A {
protected:
A() {}
}
class B : public A {}
B x; //ok
B y{}; //not ok, can't access A::A()
Would the T val = T(); example work if you don't have a copy constructor at all, or no move constructor, or custom ones which do weird things?
Edit: I checked, and you're right - the syntax seems to be fully equivalent in C++17 or later. Great to hear!
- gpderetta 3y agoPlayed it a little bit: this seems to be a regression and breaking change from C++14 where B would not be an aggregates, so B{} would just invoke the default constructor. This is probably an oversight, I wonder if there is a Defect Report. edit: it works by making the inheritance protected, as B is no longer an aggregate. The right fix would be to also disqualify B from aggregate status if the base class constructor is unreachable. Also making both A and B non-empty removes aggregate status, so it is really a dark corner of the language.