首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #include using namespace std; class TestClass { public: TestClass(int n){number=n;}
有以下程序,在横线应添加( )。 #include using namespace std; class TestClass { public: TestClass(int n){number=n;}
admin
2021-06-10
66
问题
有以下程序,在横线应添加( )。
#include
using namespace std;
class TestClass
{
public:
TestClass(int n){number=n;}
//拷贝构造函数
~TestClass(){}
private:
int number;
};
TestClass fun(TestClass P)
{
TestClass temp(p);
return temp;
}
int main()
{
TestClass obj1(10),obj2(0);
TestClass obj3(obj1);
obj2=fun(obj3);
return 0:
}
选项
A、TestClass (TestClass
&other){number=other.number;}
B、TestClass (TestClass
other){number=other.number;
C、TestClass(TestClass&other){number;}
D、TestClass(&other){number=other.number;}
答案
A
解析
拷贝构造函数也是构造函数,但它只有一个参数,这个参数是本类的对象,即other,所以赋值操作将本类的参数othernlmber赋值给number;而且采用对象的引用的形式,也就是&other。
转载请注明原文地址:https://kaotiyun.com/show/Tjfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classTestClass{public:~TestClass0{cout
下列函数声明中,错误的是
有如下程序#includeusingnamespacestd;classAA{charc;public:AA(charch):c(ch){cout
下列关于默认参数的叙述中,错误的是
请打开考生文件夹下的解决方案文件proj1,该工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句有错误。请改正这些错误,使程序的输出结果为:注意:只能修改注释“//ERROR**
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.epp,其中有类Quadritic、类Root及主函数main的定义。一个Quadritic对象表示一个ax2+bx+c的一元二次多项式。一个Root对象用于表示方程ax2+bx
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:Thereisa
下列符号中能够作为C++标识符的是()。
下列关于模板的叙述中,错误的是()。
某二叉树有5个度为2的结点,则该二叉树中的叶子结点数是()。
随机试题
简述社会主义的计划调节。
A.真性红细胞增多症B.骨髓纤维化C.珠蛋白生成障碍性贫血D.再生障碍性贫血E.缺铁性贫血泪滴形红细胞常见于
凡是反映品质标志单位组成的总体称为()。
根据《水工混凝土施工规范》DL/T5144—2001,混凝土拌合料出现下列()情况,应按不合格料处理。
设备安装标高测量时,测点的绝对标高是指测点相对于()的高程。
A公司2008年财务报表主要数据如下表所示:假设A公司资产均为经营性资产,流动负债为自发性无息负债,长期负债为有息负债,不变的销售净利率可以涵盖新增债务增加利息。A公司2009年的增长策略有两种选择:(1)高速增长:销售增长率为20%。为了筹集高速增
A、 B、 C、 C
Afterthebirthofmysecondchild,Igotajobatarestaurant.Havingworkedwithanexperienced【C1】______forafewdays,Iwa
Formilesaround,theneighborhoodswereemptyandsilent.Storesweredark,schoolsclosed,sidewalksempty.Atcorners,thest
A、Bydifferentgesture.B、Bydifferentvoice.C、Bydifferentcolor.D、Bydifferentcostume.C对话中女士提到Theypainttheirfacesindi
最新回复
(
0
)