首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #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
48
问题
有以下程序,在横线应添加( )。
#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://www.kaotiyun.com/show/Tjfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
类的析构函数的作用是()。
有如下程序:#includeusingnamespaeestd;classA{public:A(inti){x=i;}voiddispa(){cout
请打开考生文件夹下的解决方案文件proj3,其中定义了Mystring类,一个用于表示字符串的类。成员函数reverse的功能是将字符串进行“反转”。例如,将字符串ABCDEF“反转”后,得到字符串FEDCBA;将字符串ABCDEFG“反转”后,得到字符串
请打开考生文件夹下的解决方案文件proj1,该工程含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:Thevalueis10
下列有关运算符重载的叙述中,正确的是()。
下列对于软件测试的描述中正确的是()。
软件设计中模块划分应遵循的准则是()。
下列关于运算符函数的描述中,错误的是()。
Sample是一个类,执行下面语句后,调用Sample类的构造函数的次数是,()。Samplea[2],*P=newSample;
在下列关键字中,不能用来表示继承方式的是()。
随机试题
鸭爪宜整用,适于酱、卤、煮、炖等。()
创造想象
右心功能不全较早期出现的体征是
从基本医疗保险用药范围或国家和地方的“药品目录”中删除的是
要素性幻听精神分裂症最常见的情感障碍是
帽子:帽舌
建设工程项目材料设备采购招标项目,评标时要考虑的费用因素有()。
动态型信息反映某项工作的()
教学工作的基本环节是什么?
A、Todestroytreeroots.B、Todigestitsfood.C、Toprotectitsterritory.D、Tofinditsway.D由“Theknifefishproducesanelect
最新回复
(
0
)