有如下程序: #include #include using namespace std; class XCF{ int a: public: XCF(int aa=0):a(aa){cout

admin2019-04-01  14

问题 有如下程序:
    #include
    #include
    using namespace std;
    class XCF{
    int a:
    public:
    XCF(int aa=0):a(aa){cout<<"1";}
    XCF(XCF&x){a=x.a;cout<<"2";}
    ~XCF(){cout<    int Geta(){return a;}
    };
    int main(){
    XCF d1(5),d2(d1);
    XCF*pd=new XCF(8);
    cout<Geta();
    delete pd;
    return 0:
    }
    运行时的输出结果是(    )。

选项 A、1215588
B、1218855
C、12185
D、128512

答案B

解析 在这个程序中在建立对象d1(5)时,调用构造函数xCF(int aa=0):a(aa){cout<<"1";},输出1;在建立d2(d1)时,调用拷贝构造函数xcF(xCF&x){a=x.a;cout(<"2";},输出2;在建立new xCF(8)对象时,调用构造函数XCF(int aa=0):a(aa){cout<<"1";},输出1;语句cout<Geta()的功能是输出8:语句delete pd;调用析构函数~XCF(),输出8;当退出程序时,分别释放对象d2、d1,输出55。
转载请注明原文地址:https://jikaoti.com/ti/Mjt0FFFM
0

最新回复(0)