Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012/2013 in-class member initialization

This

class X
{
 int x = 2;
 string y {"smt"};
 int tab[3] = {1,2,3}; // or tab[3] {1,2,3}
};

is possible in a new C++ 11 standard, as far as i know. However none of this is allowed in Visual Studio 2012 V3 or 2013. The first one gives:

error C2864: 'A::a' : only static const integral data members can be initialized within a class

the second and third errors about the ';' and '{' .

Does it basically mean that those features are still unavailable in the MS compiler? What compiler actually supports that? I searched for the answers about in-class initialization in Visual but found nothing specific about the latest versions.

Thanks in advance.

like image 671
tomi.lee.jones Avatar asked Aug 29 '13 18:08

tomi.lee.jones


1 Answers

No, non-static data member initializers not supported by Microsoft compiler. Herb Sutter announced that it will be implemented in Visual Studio 2013 RTM. (Link)

Mr. Sutter said that main reason for such a delay in implementing C++11 features is that Microsoft trying to implement C++14 features same time, because they are tightly coupled. So, probably, we will gain some C++14 features in VS2013 release too.

Other major compilers:

  • GCC supports it (it is first complete C++11 compliant compiler since version 4.8.1 )
  • Clang supports since version 3.0
  • Intel supports since version 14
like image 51
Ivan Aksamentov - Drop Avatar answered Sep 28 '22 09:09

Ivan Aksamentov - Drop