c++11 - Initialize class member variables in C++ 11 -
consider following class definition:
class c { public: int = 9; const int j = 2; };
without using flag enable c++11 when compiling (using g++, e.g. g++ -o test test.cpp
) compiler complains on member variable initializations. however, using -std=c++11
works fine.
why has rule been changed in c++11? considered bad practice initializing member variables in manner?
initializing non-static data members @ point of declaration wasn't "bad practice"; wasn't possible at all prior c++11.
the equivalent c++03 code be:
class c { public: c() : i(9), j(2) { } int i; const int j; };
and in case: what weird colon-member syntax in constructor?
Comments
Post a Comment