问答题
请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
Constructor called of 10
The value is 10
Destructor called of 10
注意:只修改注释“//ERROR****found****”的下一行语句,不要改动程序中的其他内容。
// proj1.cpp
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass(int i)
{
value = i;
cout << "Constructor called of"<< value << endl;
}
// ERROR **********found**********
void Print()
{ cout << "The value is" << value <<endl; }
// ERROR **********found**********
void ~MyClass()
{ cout << "Destructor called of" << value << endl; }
private:
// ERROR **********found**********
int value = 0;
};
int main()
{
const MyClass obj (10);
obj.Print();
return 0;
}