以下内容是否合法?
class Aggregate {
public:
int a;
int b;
};
class Class {
public:
Class():
m_aggregate{
3,
// Here, m_aggregate.a is fully constructed, but m_aggregate is not
m_aggregate.a + 5
} {
}
Aggregate m_aggregate;
};
在聚合体的生命周期开始后但聚合体构造函数完成之前,使用聚合体的元素是否合法?
使用gcc 4.8.2测试似乎表现正常...
-Wuninitialized
,gcc 也不会发出警告。 - user1508519