diff bw initializing static int and static const int

Mar 14, 2014 at 10:23pm
class Stat
{

private:
int s;
static int num=2; //why is this a error
static const int cnum=3;//while this is perfectly fine
public:
Stat(int i=0);
void disp();
};


Why cannot i initialize "static int num" inside a class while am able ti initialize "static const int cnum".

Thanks
Mar 14, 2014 at 10:32pm
Because in case of in-class initialization of mutable variable, there is no way to determine who is going to be responsible for it's initialization between all users of header file.

Initialization of const static variables inside class declaration was forbiden too until C++11.
Topic archived. No new replies allowed.