-->
当前位置:首页 > 题库 > 正文内容

程序填空题:静态数据成员

Luz4年前 (2021-05-10)题库4101
填写程序中的空白,完成指定的功能

```c++
#include
using namespace std;
class Point{
double x,y;
@@[static int cnt;](2)//定义静态变量
public:
Point(double a=0,double b=0):x(a),y(b){
@@[cnt++;](2)
}
~Point(){
@@[cnt--;](2)
}
void show(){
cout<<"the number of Point is "<<@@[cnt](2)< }
};
@@[int Point::cnt=0;](2)
int main(){
Point p1;
Point *p=new Point(1,2);
p->show();
delete p;
p1.show();
return 0;
```
####程序输出如下:
```
the number of Point is 2
the number of Point is 1
```





答案:
第1空:static int cnt;

第2空:cnt++;

第3空:cnt--;

第4空:cnt

第5空:int Point::cnt=0;

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。