11
votes
class A 
{
public:
    A(){}

private:
    int i;
};

A a[8];

The C++11 standard 8.5.1.1 says:

"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)."

As a is an array, is a an aggregate? I think not, but the standard says yes.

1
If the Standard says so, the Standard wins :)Gorpik
@Gorpik All hail the hipno-standard! :DAdri C.S.

1 Answers

14
votes

Yes, A[8] is an aggregate type, even though A is not.

The notion of aggregate is not transitive, unlike some other related notions (such as "trivially copyable").

Loosely speaking, being an aggregate only impacts the type's initialization, and thus it does not need to be transitive. You can say A a[2] = { A('x', true), A(1, 2, 3) }; without needing to put restrictions on the nature of A. By contrast, notions like trivial copyability relate to a class's memory layout and thus by their very nature must be transitive.