Sorry that I didn't provide the link error: my_class.obj : error LNK2001: unresolved external symbol "private: static int Base::i"
Obviously, in my_class.cpp, the instruction "i=k" can't access the static data member i of MyClass.
You need to define the static members.
In my_class.cpp int MyClass::i; //initial value if you want
Yeah, your solution works.
One further question about your solution: if the int MyClass::i; is the definition of my static member, does that mean staticint i; in my_class.h is only a declaration? Then I'm a bit confused: a variable in C++ needs only declaration, doesn't it? Why do we need definition of a data member?
If I have a few more classes derived from MyClass, they will all have int i because they are derived from MyClass; However, since int i is static in the base class MyClass, all the derived classes will hence share the same int i, won't they?