首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #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
2020-07-23
63
问题
有以下程序,在横线应添加( )。
#include
using namespace std;
class TestClass
{
public:
TestClass(int n){number=n;}
//拷贝构造函数
~TestClass(){}
private:
intnumber;
};
TestClass fun(TestClass p)
{
TestClass temp(p);
retum 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,所以赋值操作将本类的参数other.number赋值给number;而且采用对象的引用的形式,也就是&other。
转载请注明原文地址:https://www.kaotiyun.com/show/72yp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
关于函数声明格式中的,下列叙述错误的是
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
有如下类定义:classMyClass{public:_____________private:intdata;};若要为MyCla
结构化程序设计中,下面对goto语句使用描述正确的是
有如下类及函数的定义:classWow{intk;public:Wow(intn=0):k(n){}intincre(){return++k;}
已知主函数中通过如下语句序列实现对函数模板swap的实例调用:inta[10],b[10];swap(a,b,10);下列对函数模板swap的描述中,会导致上述语句序列发生编译错误的是
派生类的成员函数不能访问基类的()。
派生类的成员函数不能访问的基类成员是
模板对类型的参数化提供了很好的支持,因此()。
下列符号中,正确的C++标识符是()。
随机试题
按油气田、油气藏或开发区块的第一个汉字名称命名的井是()。
Asiais()amongthesevencontinents.
必须应用造影剂进行的检查是
A.相须B.相使C.相畏D.相杀E.相恶绿豆相对于巴豆而言其配伍关系是
根管最狭窄的地方在哪里
肛门直肠周围脓肿破溃后每多形成()
生活垃圾填埋工程中,泥质防渗层施工技术的核心是()施工技术。
幼儿园教育活动的组织应注重()
minimizeslatenessandabsenteeismstarttelecommutingprogramstelecommutingrealitiesandpopularimagestothequietAdiro
LatinoyouthsneedbettereducationforArizonatotakefulladvantageofthepossibilitiesthen-explodingpopulationoffers.Ar
最新回复
(
0
)