Why the static data members have to be defined outside the class separately in C++ (unlike Java)?

Posted by iammilind on Programmers See other posts from Programmers or by iammilind
Published on 2012-04-20T05:12:01Z Indexed on 2012/11/18 11:25 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|
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) ?

© Programmers or respective owner

Related posts about c++

Related posts about language-features