且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

g ++ 4.9拒绝C ++ 14中的有效聚合初始化

更新时间:2023-11-09 08:54:04

正确,这是有效的C ++ 14;然而,在C ++ 11中,类成员初始化中的类不是聚合,因此在C中无效++ 11。

You are correct, this is valid C++14; however, in C++11 a class with in class member initializers was not an aggregate and so this is not valid in C++11.

我在回答上述问题时提到的问题,后来我发表了我的初步意见后意识到, gcc不支持此更改,直到5.0 查看活动

The issue as I noted in my answer to the above question and I realized later after I made my initial comment is that gcc did not support this change until 5.0 (see it live):


支持具有非静态数据成员
初始化器的C ++ 14聚合。

G++ now supports C++14 aggregates with non-static data member initializers.

struct A { int i, j = i; };
A a = { 42 }; // a.j is also 42