diff bw initializing static int and static const int

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
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.