Topic: Nested aggregate initialization question
Author: jzipnick@best.com (Jay Zipnick)
Date: 1997/04/24 Raw View
Is the initializer of aggregate t4 legal in the code below?
---------------------------------------
struct AB
{
int a;
int b;
};
struct ABC
{
AB ab;
int c;
};
AB t1 = { 1, 2 }; // brace-enclosed initializer for aggregate AB
AB t2 = t1; // t1 is a valid initializer for aggregate AB
ABC t3 = { { t1.a, t1.b }, 3 }; // OK
ABC t4 = { t1, 3 }; // IS THIS LEGAL?
---------------------------------------
I would believe the initializer for t4 is legal, because of
paragraph 3 of section 8.5.1 (below), Is it?
"1) An aggregate is an array or a class (9) with no user-declared
constructors (12.1), no private or protected non-static data
members (11), no base classes (10), and no virtual functions (10.3).
2) When an aggregate is initialized the initializer can be an
initializer-clause consisting of a brace-enclosed, comma-separated
list of initializers for the members of the aggregate, written in
increasing subscript or member order. If the aggregate contains
subaggregates, this rule applies recursively to the members of the
subaggregate.
3) An aggregate that is a class can also be initialized with a
single expression not enclosed in braces, as described in 8.5."
- Jay Zipnick
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]