为什么我得到的非聚合不能用初始化器列表初始化

时间:2022-05-27 18:03:23
std::map<std::string, int> m = {
    {"Marc G.", 123},
    {"Zulija N.", 456},
    {"John D.", 369}
};

In Xcode I have C++ Language Dialect set to "C++0x [-std=c++0x]" and C++ Standard Library set to "libc++ LLVM C++ Standard library with C++0X Support"

在Xcode中,我将c++语言方言设置为“c++0x [-std=c++0x]”,c++标准库设置为“使用c++0x支持的libc++ LLVM c++标准库”。

Do I need to set something else?

我需要设置其他东西吗?

2 个解决方案

#1


30  

EDIT 10/2013: this answer is really old, Apple Clang does support this now.

编辑10/2013:这个答案很老,苹果公司现在确实支持这个。

C++11 Initializer Lists are not yet supported as of Clang 3.0

c++ 11初始化器列表还没有得到Clang 3.0的支持。

See the implementation status here: Clang C++11 implementation status

参见这里的实现状态:Clang c++ 11实现状态。

(Your syntax looks correct if only the compiler supported this feature)

(如果编译器支持这个特性,那么语法看起来是正确的)

#2


12  

Clang 3.6.2 supports initializer-list syntax. Just remember to pass -std=c++11 flag when compiling.

Clang 3.6.2支持initializer-list语法。记住在编译时要传递-std=c++11标志。

#1


30  

EDIT 10/2013: this answer is really old, Apple Clang does support this now.

编辑10/2013:这个答案很老,苹果公司现在确实支持这个。

C++11 Initializer Lists are not yet supported as of Clang 3.0

c++ 11初始化器列表还没有得到Clang 3.0的支持。

See the implementation status here: Clang C++11 implementation status

参见这里的实现状态:Clang c++ 11实现状态。

(Your syntax looks correct if only the compiler supported this feature)

(如果编译器支持这个特性,那么语法看起来是正确的)

#2


12  

Clang 3.6.2 supports initializer-list syntax. Just remember to pass -std=c++11 flag when compiling.

Clang 3.6.2支持initializer-list语法。记住在编译时要传递-std=c++11标志。