countP是静态变量,用来统计实例的个数,所以在构造函数和拷贝构造函数中,让countP++(实例个数增加1),在析构函数中countP--(实例销毁后数量-1)
在第5个空的地方,把countP初始化为0,填空如下:
(1)countP++ 或者 countP+=1
(2)countP++ 或者 countP+=1
(3)countP
(4)countP--
(5)Point::countP = 0
代码:
class Point
{
public:
Point(int xx=0,int yy=0)
{
X=xx;Y=yy;countP++; //(1)
}
Point(Point& p){X=p.X;Y=p.Y;countP++;}//(2)
int GetX(){return X;}
int GetY(){return Y;}
static void GetC()
{
cout <<"Object id="<<countP<<endl;//(3)
}
~Point(){countP--;}//(4)
private:
int X,Y;
static int countP;
};
int Point::countP =0; //(5)