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.
5.5.The most common aggregate data type is an array. An array contains zero or more values of the same data type, such as characters, integers, floating point numbers, or fixed point numbers. An array may also be contain values of another aggregate data type. Every element in an array must have the same type.
There are three different kinds of arrays: indexed arrays, multidimensional arrays, and associative arrays.
An array type is a user-defined data type consisting of an ordered set of elements of a single data type. An ordinary array type has a defined upper bound on the number of elements and uses the ordinal position as the array index.
What Are Arrays in Data Structures? An array is a linear data structure that collects elements of the same data type and stores them in contiguous and adjacent memory locations. Arrays work on an index system starting from 0 to (n-1), where n is the size of the array.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With