高等继续教育 / 面向对象程序设计
正确率:推荐%
题型描述: 简答题
下面程序的执行结果是什么?
#include<iostream>
using namespace std;
class goods{
private:
static int totalweight;
int weight;
public:
goods(int w){
weight=w;
totalweight+=weight;
}
goods(goods& gd){
weight=gd.weight;
totalweight+=weight;
}
~goods(){
totalweight-=weight;
}
static int gettotal(){
return totalweight;
}
};
int goods::totalweight=0;
int main(){
goods g1(50);
cout<<goods::gettotal()<<endl;
goods g2(100);
cout<<g2.gettotal()<<endl;
return 0;
}
参考答案:
佳题速递: