且构网

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

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

更新时间:2023-11-09 08:58: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):

G++ 现在支持具有非静态数据成员的 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