首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #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
64
问题
有以下程序,在横线应添加( )。
#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://kaotiyun.com/show/72yp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下函数定义:voidfunc(inta,int&b){a++;b++;}若执行代码段:intx=0,y=1;func(x,y);则变量x和y的值分别是()。
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
下面属于白盒测试方法的是
有如下程序:#include#includeusingnamespacestd;classAnimal{public:virtualstring
如果派生类以protected方式继承基类,则基类中的保护成员在派生类中的访问属性是
有如下类声明和函数声明:classBase{intm;public:intn;protected:intp;};classDe
下列有关函数重载的叙述中,错误的是()。
下列有关类继承的表述中,错误的是
下列关于运算符重载的叙述中,错误的是
随机试题
水利水电工程中,水电站的布置形式是利用引水道来集中河段落筹形成发电水头的水电站,这种形式称为()。
A、油管B、油室C、油细胞D、树脂道E、乳管人参组织中有()
输血过程中下列哪项不妥( )。
与散发性先天性甲状腺功能减低症病因无关的是
新生儿期喂养,最好的食物是
在上述甲公司所签订的合同中( )。法律规定应当采用书面形式的合同,当事人未采用书面形式,但已履行了全部或者主要义务的,应视为( )。
发展心理咨询的主要目的是()。
按照伯克威茨的观点,侵犯行为的发生,除了与挫折导致的愤怒情绪有关系外,还受()的影响。
WheneverIamintrouble,heissuretohelpmeout.I’ve________.
A、Onholiday.B、Onbusiness.C、Thegreatlakes.D、Intheoffice.B题目询问男士去了哪里。关键是听到negotiations一词,就可以判断选项B(出差)是正确的。
最新回复
(
0
)