Visual Studio 2012/2013 class member initialization

it

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

possible in the new C ++ 11 standard, as far as I know. However, none of these are allowed in Visual Studio 2012 V3 or 2013. The first gives:

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

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

Does this basically mean that these functions are still not available in the MS compiler? Which compiler really supports this? I searched for class initialization answers in Visual, but did not find anything specific about the latest versions.

Thanks in advance.

+4
source share
1 answer

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

Mr. Sutter said that the main reason for this delay in implementing the capabilities of C ++ 11 is that Microsoft is trying to implement the capabilities of C ++ 14 at the same time, because they are closely related. Thus, probably, we will also get some C ++ 14 features in VS2013 version.

Other main compilers:

  • GCC supports it (this is the first full C ++ 11 compiler compatible with version 4.8.1)
  • Clang supports since version 3.0
  • Intel supports since version 14
+7
source

Source: https://habr.com/ru/post/1499678/


All Articles