问题
填空题
试题源程序文件清单如下:
//proj1. cpp
#include<iostream>
using namespace std;
class MyClass
public:
MyClass():count(0) cout<<"This object is";
//ERROR********found********
void Inc() const (1)
cout<<"no."<<++count<<endl;
private:
//ERROR********found********
int count=0;(2)
;
int main()
MyClass*obj=new MyClass;
//ERROR********found********
* obj.Inc(); (3)
return 0:
答案
参考答案:void Inc()
解析: 常函数不能改变数据成员count的值。按照题目要求的输出,函数体确实需要在此改变count的值,所以应该去掉const关键字。