A simple question, why "const static" class member can be initialized inside declaration?

I know why non-const static member cannot be initialized inside class declaration. It is because class declaration doesn't allocate memory space. It's just a description.

But why const static member escape this concept? Won't it just to facilitate my coding?

1
2
3
4
class test{
const static int m = 10;//ok, but why?
static int n = 11;//error
};
Last edited on
All static data members of a class have external linkage; whether const or not.

> But why const static member escape this concept? Won't it just to facilitate my coding?

The brace-or-equal-initializer allowed as part of the declaration of a non-volatile const static data member of integral type is to facilitate its use in constant expressions.
Topic archived. No new replies allowed.