C ++ 11 now supports setting the value of a member field of a class during declaration, for example:
class MyClass { private int test = 0; }
If I also initialize the variable in the constructor as follows:
class MyClass { private int test = 0; public: MyClass() : test(1) { } }
will this cause the variable to have a value set twice, or does the specification indicate that the compiler should optimize this to initialize the variable only once? If the specification dictates nothing, do you know the behavior of well-known compilers (e.g. MSVC, GCC, etc.) regarding this?
c ++ c ++ 11
Rafid
source share