C++ Logo

std-discussion

Advanced search

Elements of an aggregate in C++ 20.

From: Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Date: Fri, 15 Nov 2019 16:00:35 +0300
The following phrase from the C++ Standard (9.3.1 Aggregates, p. #2) confuses

2 The elements of an aggregate are:
(2.2) — for a class, the direct base classes in declaration order, followed by the direct non-static data members (11.3) that are not members of an anonymous union, in declaration order.

Should is there the word "recursively" be inserted somewhere in the phrase relative to the direct base classes?

This would make for example this initialization more clear

#include <iostream>
struct A
{
int x;
};
struct B : A
{
int y;
};
struct C : B
{
int z;
};
int main()
{
C c = { { { .x = 10 }, 20 }, 30 };

std::cout << "c.x = " << c.x << ", " << "c.y = " << c.y << ", c.z = " << c.z << '\n';
}
  With best regards,

Vlad from Moscow

You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

Received on 2019-11-15 07:02:57