c++ - 为什么 GCC 6.3 在没有明确 C++11 支持的情况下编译这个 Braced-Init-List 代码?

标签 c++ gcc initializer-list c++03 list-initialization

我有一个关于 the different meanings of a curly-brace enclosed list 的问题.

我知道 C++03 不支持 C++11 的 initializer_list。然而,即使没有 -std=c++11 编译器标志,gcc 6.3 will properly initialize interpolate使用此代码:

map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };

I was challenged关于为什么这会起作用,我意识到我没有答案。这是一个 Brace-Init-List,但我们从中获得初始化标准容器的方式通常是通过 initializer_list。那么非 C++11 代码如何完成初始化呢?

最佳答案

default compiler command for gcc 6.x is -std=gnu++14 ,因此编译器使用更高版本的 C++ 语言标准隐式编译您的代码。

如果要在 C++03 中编译,则需要手动指定 -std=c++03

关于c++ - 为什么 GCC 6.3 在没有明确 C++11 支持的情况下编译这个 Braced-Init-List 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44654713/

相关文章:

c++ - 将数组传递给模板函数

c++ - Qt5 : Strange compilation error while using QCommandLineParser class

c - GCC 程序未定义对函数的引用(多个文件夹)

c++ - 对非对象使用成员初始化列表不好吗?

c++ - 自定义 vector 类的构造方法,将额外的垃圾值分配给指针

java - 在 Android Studio 3 中设置 JNI

c++ - 在插入或移除时获取 USB 的 dos_name

C++ std::stringstream 似乎导致线程在 SunOS 下挂起或死亡

c++ - 虚假 "missing sentinel in function call"

c++ - 没有用于初始化“listNode 结构”的匹配构造函数