单选题
C++
题号 #2251374
有如下程序:
#include(iostream>
usingnamespacestd;
classCon
{
charID;
public:
Con( ):ID('A){cout<<1;}
Con(charID):ID(ID){cout((2;)
Con(Con8Lc):ID(c.getlD( )){cout<<3;}
chargetID( )const{returnID;}
};
voidshow(Conc){cout<<C.getlD( );}
intmain( )
{
Conc1;
show(c1);
Conc2('B');
show(c2);
return0;
执行上面程序的输出结果是( )。
参考答案
C
答案解析
C。【解析】Concl定义cl对象,调用Con的无参数构造函数,输出1,ID值变为A,执行show(c1)时会调用拷贝构造函数,将cl对象的值复制给show函数的形参,此时输出3,然后在show()中输出cl的lD值A,Conc2('B')定义c2对象,调用Con(charID)构造函数,输出2,c2的ID值为B,show(c2)执行时先调用拷贝构造函数输出3,然后输出B。因此程序输出结果为“13A23B”。
你可能感兴趣的试题
A.69825
B.63825
C.6385
D.693825
A.This
B.This is
C.This is a
D.This is an example
A.MyClassmy;my.value=10;
B.MyClassmy;*my.value=10;
C.MyClassmy;my.*value=10;
D.MyClassmy(10);