From C++ Draft Standard n3337:
8.5.1 Aggregates [dcl.init.aggr]
1 An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equalinitializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
Say I have two classes:
struct ABase
{
int value;
};
struct A : public ABase {};
Based on the standard, ABase
is an aggregate type while A
is not. That means, it's OK to create an instance of ABase
using:
ABase a1{10};
but it's not OK to create an instance of A
using:
A a2{20};
A
is trivially derived from ABase
and could potentially have been treated as an aggregate. My question is what sorts of pitfalls one, a user of the language as well as an implementor of a compiler, can run into by treating A
as an aggregate type?