Consider the following class definition:
class C {
public:
int i = 9;
const int j = 2;
};
Without using the flag to enable C++11 when compiling (using g++, e.g. g++ -o test test.cpp
) the compiler complains on the member variable initializations. However, using -std=c++11
this works fine.
Why has this rule been changed in C++11? Is it considered bad practice initializing member variables in this manner?