Why can I not brace initialize a struct derived from another struct?
问题 When I run this code: struct X { int a; }; struct Y : public X {}; X x = {0}; Y Y = {0}; I get: error: could not convert ‘{0}’ from ‘<brace-enclosed initializer list>’ to ‘Y’ Why does brace initialization work for the base class but not the derived class? 回答1: Your problem has to do with aggregate initialization: struct X is an aggregate while struct Y is not. Here is the standard quote about aggregates (8.5.1): An aggregate is an array or a class (Clause 9) with no user-provided constructors