使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,并且使程序输出的结果为: CMyObject,in the construtor ~CMyObject,in the destru

admin2017-03-22  23

问题 使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,并且使程序输出的结果为:
    CMyObject,in the construtor
    ~CMyObject,in the destrutor
    注意:错误的语句在//********error********的下面,修改该语句即可。
#include
class CMyObject
{
    //********error********
    //********error********
    CMyObject{cout<<"CMyObject,
in the constrUtor"<    ~CMyObject(){cout<<
"~CMyObject,in the destrutor"
<};
Void main()
{
    CMyObject obj1;
}

选项

答案(1)添加语句:public: (2)CMyObject(){cout<<"CMyObject,in the construtor"<
解析 (1)构造函数和析构函数均为公有函数,而在C++中默认的访问属性为私有(private),因此构造函数和析构函数必须说明为public,即第1个标识下应添加“public:”。
    (2)函数定义中在函数名后均有一对括号表示函数声明,因此第2个标识下应改为“  CMyObjectO{cout<<    "CMyObject,in theconstrutor"<
转载请注明原文地址:https://kaotiyun.com/show/39Ap777K
0

最新回复(0)