Why the static data members have to be defined outside the class separately in C++ (unlike Java)?
https://softwareengineering.stackexchange.com/questions/145299
-
04-11-2019 - |
题
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) ?
没有正确的解决方案