C++静态成员
#include<iostream>
using namespace std;
class box
{
public:
box(int,int);
int volume();
static int height;
int width;
int length;
};
box::box(int w,int l)
{
width=w;
length=l;
}
int box::volume()
{
return (height*width*length);
}
int height=10;
int main()
{
box a(18,19),b(30,20);
cout<<"a.height"<<a.height<<endl;
cout<<"b.height"<<b.height<<endl;
cout<<"box::height"<<box::height<<endl;
cout<<"a.volume()"<<a.volume()<<endl;
return 0;
}
编译之后怎么出现这个问题
zzzzzz.obj : error LNK2001: unresolved external symbol "public: static int box::height" (?height@box@@2HA)
Debug/zzzzzzz.exe : fatal error LNK1120: 1 unresolved externals
[解决办法]