Initializer list not working with vector in Visual Studio 2012? [duplicate]

梦想与她 提交于 2019-12-17 07:43:06

问题


Possible Duplicate:
C++11 features in Visual Studio 2012

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" }; 

When I try the following in Visual Studio 2012 I get the compilation error C2552: 'vecs' : non-aggregates cannot be initialized with initializer list

Here is my code:

#include <vector>

using namespace std;

int main() {
    vector<string> vecs = {"h", "g", "e"};
}

Does VS2012 not support initializer lists or am I just misunderstanding something?

Thanks!


回答1:


Visual Studio 2012 does not support initializer lists.

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.



来源:https://stackoverflow.com/questions/12654394/initializer-list-not-working-with-vector-in-visual-studio-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!