我如何访问这个使用 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/