首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++静态成员解决方法

2013-11-14 
C++静态成员#includeiostreamusing namespace stdclass box{public:box(int,int)int volume()static

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
[解决办法]

引用


改为int box::height=10;

热点排行