diff bw initializing static int and static const int

class Stat

int s;
static int num=2; //why is this a error
static const int cnum=3;//while this is perfectly fine
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".

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.