Why the static data members have to be defined outside the class separately in C++ (unlike Java)?
- by iammilind
class A {
static int foo () {} // ok
static int x; // <--- needed to be defined separately in .cpp file
};
I don't see a need of having A::x defined separately in a .cpp file (or same file for templates). Why can't be A::x declared and defined at the same time?
Has it been forbidden for historical reasons?
My main question is, will it affect any functionality if static data members were declared/defined at the same time (same as Java) ?