GCC 编译器警告:扩展初始化列表仅适用于 c++0x

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1863827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:27:03  来源:igfitidea点击:

GCC Compiler Warning: extended initializer lists only available with c++0x

c++gccwarnings

提问by Anonymous

Using this member initialization...

使用这个成员初始化...

StatsScreen::StatsScreen( GameState::State level )
    : m_Level( level ) {
  ...//
}

I get the following warning...

我收到以下警告...

extended initializer lists only available with -std=c++0x or -std=gnu++0x

extended initializer lists only available with -std=c++0x or -std=gnu++0x

Any information regarding this warning?

有关此警告的任何信息?

Edit: Warning went away after I removed one of the member that was assigned to a value inside the constructor (couldn't be done through member initialization) and made it a local variable instead of a class member. Still want to know what that warnings means though.

编辑:在我删除了分配给构造函数内部值的成员之一(无法通过成员初始化完成)并将其设为局部变量而不是类成员后,警告消失了。仍然想知道这些警告是什么意思。

回答by AraK

I think you are initializing the object with {...}instead of (...):

我认为您正在使用{...}而不是初始化对象(...)

StatsScreen ss{...}; // only available in C++0x
StatsScreen ss(...); // OK in C++98

To compile your code as C++0x code, just add the following flag when compiling:

要将您的代码编译为 C++0x 代码,只需在编译时添加以下标志:

g++ test.cpp -std=c++0x