c++ - 二进制 '[' : 'std::initializer_list<const char *>' does not define this operator or a conversion to a type acceptable to the predefined operator

标签 c++ c++11 visual-studio-2013

我如何访问这个使用 auto 关键字声明的初始化器的值?

auto arr = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
auto a = arr[0];

在 VS 上给出以下编译错误:

binary '[' : 'std::initializer_list' does not define this operator or a conversion to a type acceptable to the predefined operator

最佳答案

看看std::initializer_list的界面:

auto arr = { "one", "two", "three", "four", "five", "six",
              "seven", "eight", "nine" };
auto a = *arr.begin();

(或者,更实际一点,用你的 braced-init-list 初始化一个容器或数组)

关于c++ - 二进制 '[' : 'std::initializer_list<const char *>' does not define this operator or a conversion to a type acceptable to the predefined operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24345100/

相关文章:

c++ - 将窗口放在前面 -> raise()、show()、activateWindow() 不起作用

c++ - 在编译时初始化 c++ std::bitset

c++ - VC2013 : function from bind not compiling

C++ MSC_VER 与第三方库不匹配

visual-studio-2013 - Script# 是否与 Visual Studio 2013 一起使用?

C++ DAL 设计 - 将外键表包含为复合对象

php - 如何在 php 扩展中包装 c++ 类?

c++ - QTimeEdit C++ 删除填充

c++ - 重载运算符返回的对象在 C++ 中丢失数据

c++ - std::thread 从线程函数内部释放