28

I had some code that I developed on Ubuntu and now I am trying to compile it on Windows 7 (MS VS 2010).

vector<float> tmp;
....
tmp = {3.0,4.5,9.4};

This gives me syntax error

error C2143: syntax error : missing ';' before '{'

Is this because Visual studio doesn't support this feature ? or should I be enabling some switch in the properties. I have the "Platform Toolset" property set to "v100."

Thank you.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Chenna V
  • 10,185
  • 11
  • 77
  • 104
  • 3
    For reference on C++0x support in current compilers, check Apache stdcxx's page: http://wiki.apache.org/stdcxx/C%2B%2B0xCompilerSupport - only GCC 4.4+ has initializer lists. – wkl Feb 25 '11 at 19:13

3 Answers3

33

The C++0x features are enabled by default on the Visual Studio 2010 C++ compiler. It takes no extra switches for example to use lambdas, auto, etc ... If you're getting that error it's because in all likelyhood it's not supported.

EDIT

Based on this MSDN article, initializer lists are not one of the 6 supported features in 2010

the Visual C++ compiler in Visual Studio 2010 enables six C++0x core language features: lambda expressions, the auto keyword, rvalue references, static_assert, nullptr and decltype

Joey
  • 344,408
  • 85
  • 689
  • 683
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
16

Visual Studio 2010 doesn't support initializer lists. Look here for the supported C++0x features in Visual Studio 2010

Visual Studio 2012 doesn't support them, too. You can find he C++11 features that are implemented in Visual Studio 2012 / VS11 here and here.

The first implementation of initializer list is available in the Visual C++ Compiler November 2012 CTP.

The first real release of initializer lists will be in Visual Studio 2013.

Community
  • 1
  • 1
Fox32
  • 13,126
  • 9
  • 50
  • 71
3

Even if they were there, this code would not work because it assigns an initializer list, which is not yet a vector, to an existing object named 'tmp'. You can assign to vectors like this:

vector<int> tmp = vector<int> {...}; // calls constructor, initializes then assigns

or

std::initializer_list<int> iniList = {1,2,3,4,5,6};

but not

std::vector<int> tmp;
tmp = {...}; // calls assignment operator

By the way: the feature is still missing in VS2012.