问答题
请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1。程序中位于每个“//ERROR ****found****”下一行的语句有错误,请加以改正。改正后程序的输出结果应为:
Thp value is 5
The value is 10
There are 2 objects.
There are 1 objects.
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass(int value)
{
// ERROR ********** found**********
this.value = value;
count ++;
}
// ERROR ********** found**********
void ~MyClass()
{
count--;
}
static int getCount () { return count; }
int getValue() { return value; }
private:
int value;
static int count;
};
// ERROR ********** found**********
static int MyClass::count = 0;
int main()
{
MyClass* p = new MyClass(5);
MyClass* q = newMyClass(10);
cout << "The value is" << p ->getValue() << endl;
cout << "The value is" << q ->getValue() << endl;
cout << "There are" << MyClass::getCount() << " objects." << endl;
delete p;
cout << "There are" <, MyClass::getCount() << "objects." << endl;
return 0;
}
【参考答案】
(1)this->value=value;
(2)~MyClass()
(3)int MyClass::count=0;