首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #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
36
问题
有以下程序,在横线应添加( )。
#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://jikaoti.com/ti/F8l0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
关于函数声明格式中的,下列叙述错误的是
下列代码段中声明了3个类:classPerson{};classStudent:publicPerson{};classUndergraduate:Student{};下列关于这些类之间关系的描述中,错误的是()。
数据库中对概念模式内容进行说明的语言是
有如下类定义:classPoint{public:voidSetX(intxx){x=xx;}protected:voidSetY(intyy)
结构化程序设计中,下面对goto语句使用描述正确的是
有如下程序:#includeusingnamespacestd;classBase{public:Base(){cout
有如下类声明和函数声明:classBase{intm;public:intn;protected:intp;};classDe
有如下类声明:classBase1{};classBase2{};classDerived:publicBase2,publicBase1{};在一个Derived对象消亡时,析构函数被调用的顺序
下列有关函数重载的叙述中,错误的是()。
下列字符串中,不可以用做C++标识符的是()。
随机试题
患者女,75岁,左眼视力光感,定位准,晶状体混浊,核呈褐色,应选用的术式为
由于房地产价值量大,加之独一无二特性造成对影响房地产价格的()等方面的情况在短时间内不易了解。
下列选项内容属于初步评审中响应性评审标准的有()。
证券投资分析中公司分析的对象主要是()。
失独家庭可领养子女,民政局要统计各区县人数。想要做一个调查。让你组织,你怎么做?
正常利润是()的一个组成部分。
下列关于我国审判机关的表述,正确的是()。
What’saman?Or,indeed,awoman?Biologically,theanswermightseemobvious.Ahumanbeingisa(n)【C1】______whohasgrownfr
Itwasjustafootnotecomparedwiththemoreinfectiousdisasterthatkilledmillionsmorepeoplein1918,butthe1957influen
请使用VC6或使用【答题】菜单打开考生文件夹pmjl下的工程proj1。此工程中包括类Date(“13期”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:20
最新回复
(
0
)