V
vib.cpp
#include <iostream.h>
class Cat
{
public:
static HowManyCats;
private:
int itsage;
};
int Cat::HowManyCats=5;
int main()
{
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}
The above is right, but the below is wrong, why cannot I declare
static data member in the class which it belong to?
#include <iostream.h>
class Cat
{
public:
static int HowManyCats;
private:
int itsage;
};
Cat::HowManyCats=5;
int main()
{
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}
The following is still not true, why? can I declare the static member
inside the main function? And if I remove the int from the int
Cat::HowManyCats=5;statement, it passed the compile, but still blocked
when building, can anybody explain this for me?
#include <iostream.h>
class Cat
{
public:
static HowManyCats;
private:
int itsage;
};
int main()
{
int Cat::HowManyCats=5;
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}
class Cat
{
public:
static HowManyCats;
private:
int itsage;
};
int Cat::HowManyCats=5;
int main()
{
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}
The above is right, but the below is wrong, why cannot I declare
static data member in the class which it belong to?
#include <iostream.h>
class Cat
{
public:
static int HowManyCats;
private:
int itsage;
};
Cat::HowManyCats=5;
int main()
{
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}
The following is still not true, why? can I declare the static member
inside the main function? And if I remove the int from the int
Cat::HowManyCats=5;statement, it passed the compile, but still blocked
when building, can anybody explain this for me?
#include <iostream.h>
class Cat
{
public:
static HowManyCats;
private:
int itsage;
};
int main()
{
int Cat::HowManyCats=5;
cout<<"HowManyCats="<<Cat::HowManyCats<<endl;
}