Initializer list not working with vector in Visual Studio 2012?(初始值设定项列表不适用于 Visual Studio 2012 中的向量?)
问题描述
可能的重复:
Visual Studio 2012 中的 C++11 功能
所以我今天通过 维基百科阅读了 C++11 初始值设定项列表 并看到 C++11 支持标准容器的以下语法:
So I was reading up on C++11 initializer lists today via Wikipedia and saw that C++11 supports the following syntax for the standard containers:
std::vector<std::string> v = { "xyzzy", "plugh", "abracadabra" };
std::vector<std::string> v({ "xyzzy", "plugh", "abracadabra" });
std::vector<std::string> v{ "xyzzy", "plugh", "abracadabra" };
当我在 Visual Studio 2012 中尝试以下操作时,出现编译错误 C2552: 'vecs' : non-aggregates cannot be initialized with initializer list
When I try the following in Visual Studio 2012 I get the compilation error C2552: 'vecs' : non-aggregates cannot be initialized with initializer list
这是我的代码:
#include <vector>
using namespace std;
int main() {
vector<string> vecs = {"h", "g", "e"};
}
VS2012 不支持初始化列表还是我误解了什么?
Does VS2012 not support initializer lists or am I just misunderstanding something?
谢谢!
推荐答案
Visual Studio 2012 不支持初始化列表.
Visual Studio 2012 does not support initializer lists.
嗯,直到 2012 年 11 月 CTP 才出现.现在确实如此,至少处于 alpha 状态.当然,这段代码仍然无法在其中工作,因为他们仍在将初始化列表放入标准库本身.
Well, it didn't until the November 2012 CTP. Now it does, at least in an alpha state. Granted, this code still won't work in it because they're still putting initializer lists into the standard library itself.
这篇关于初始值设定项列表不适用于 Visual Studio 2012 中的向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:初始值设定项列表不适用于 Visual Studio 2012 中的向量?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
