25

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!

Community
  • 1
  • 1
DigitalZebra
  • 39,494
  • 39
  • 114
  • 146

1 Answers1

38

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 2
    Thanks Nicol, here is a fairly good table describing the list of features VS2012 supports: http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx – DigitalZebra Sep 29 '12 at 16:39
  • 1
    The support is atrocious though. `int main() { for (int i : {1, 2, 3, 4, 5}) { } }` gives an internal compiler error. [edit] actually, the pre-CTP one crashes. The CTP one just lacks the begin / end functions for initializer lists. – dascandy Jul 14 '13 at 18:23
  • @dascandy: Yes. That's part of the lack of standard library support for initializer lists: not having proper overloads for std::begin and std::end, which ranged-based `for` relies on. – Nicol Bolas Jul 15 '13 at 06:03
  • Hmm it's 2015 and VS 2012 still doesn't seem to support it.. – Claudiu Apr 16 '15 at 01:47