16,551
社区成员
发帖
与我相关
我的任务
分享
cout<<"rect2调用getTotalCount值:"<<rect2.getTotalCount()<<endl;
class Graph
{
public:
Graph(){ s_gCount++; }
~Graph() { s_gCount--;}
virtual int drawOut() = 0;
static int getTotalCount() { return s_gCount; }
protected:
int m_x;
int m_y;
static int s_gCount;
};
int Graph::s_gCount = 0;
class Rectangel : public Graph
{
public:
int drawOut()
{
cout<<"实现drawOut"<<endl;
return 0;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
if(1)
{
cout<<"构造Rectangel对象:rect1"<<endl;
Rectangel rect1;
cout<<"rect1调用getTotalCount值:"<<rect1.getTotalCount()<<endl;
cout<<"构造Rectangel对象:rect2"<<endl;
Rectangel rect2;
cout<<"rect1调用getTotalCount值:"<<rect1.getTotalCount()<<endl;
cout<<"rect2调用getTotalCount值:"<<rect1.getTotalCount()<<endl;
}
cout<<"rect1和rect2对象的生命期结束"<<endl;
cout<<"构造Rectangel对象:rect3"<<endl;
Rectangel rect3;
cout<<"rect3调用getTotalCount值:"<<rect3.getTotalCount()<<endl;
return 0;
}