class A
{
static int a;
public:
static ini(int b)
{
a=b;
}
};
int main()
{
A a1;
a1.ini(3);
}
报错:
const error LNK2001: unresolved external symbol "private: static int A::a" (
?a@A@@0HA)
谢谢
l*****d 发帖数: 359
2
it seems you have to define a just below the class declaration:
int A::a;
then it should be ok.
【在 j*****j 的大作中提到】 : class A : { : static int a; : public: : static ini(int b) : { : a=b; : } : }; : int main()
l*****d 发帖数: 359
3
The declaration of a static data member in the member list of a class is not
a definition. The definition of a static data member is equivalent to an
external variable definition. You must define the static member outside of
the class declaration in namespace scope.
For example:
class X
{
public:
static int i;
};
int X::i = 0; // definition outside class declaration