首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序,在横线应添加( )。 #include<iostream> using narnespace std; class TestClass { public: TestClass int n){
有以下程序,在横线应添加( )。 #include<iostream> using narnespace std; class TestClass { public: TestClass int n){
admin
2020-11-11
72
问题
有以下程序,在横线应添加( )。
#include<iostream>
using narnespace 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(TestClms &other){number;}
D、TestClass(&other){number=other.number;}
答案
A
解析
拷贝构造函数也是构造函数,但它只有一个参数,这个参数是本类的对象,即other,所以赋值操作将本类的参数other.number赋值给number;而且采用对象的引用的形式,也就是&other。
转载请注明原文地址:https://kaotiyun.com/show/svyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:usingnamespacestd;classB{public:B(intxx):x(xx){++count;x+=10;}virtualvoidshow()const{c
有如下程序#include<iostream>usingnamespacestd;classA{public:virtualvoidfunc1(){cout<<’’A1’’;}voidf
已知在一个类体中包含如下函数原型:VOLUMEoperator-(VOLLIME)const;,下列关于这个函数的叙述中,错误的是()。
下列有关内联函数的叙述中,正确的是()。
下列叙述中正确的是()。
有如下程序:#inc1ude<iostream>usingnamespacestd;c1assComp1ex{doublere,im;public:Comp1ex(double
如果不使用多态机制,那么通过基类的指针虽然可以指向派生类对象,但是只能访问从基类继承的成员。有如下程序,没有使用多态机制。#inc1ude<iostream>usingnamespacestd;c1assBase{
算法分析的目的是
程序流程图中带有箭头的线段表示的是
随机试题
若银行贷款利率为7.67%,存款利率为5.67%,综合考虑确定企业所处行业的风险报酬率为5%,则该企业拟采用的折现率为()
下列哪项构成直疝三角
《神农本草经》收载药物
从事证券、期货投资咨询业务的人员,必须取得证券、期货投资咨询从业资格并加入一家有从业资格的证券、期货投资咨询机构后,方可从事证券、期货投资咨询业务。()
在面试过程中,考官应当表现出的行为是()。
静力性工作有哪些类型?请分别举例说明。
坚持唯物辩证法,反对形而上学,是建设中国特色社会主义的根本要求。()
下列叙述中正确的是
Accordingtothetext,foodhabitsareveterminedbyallofthefollowingexcept______.Thereasonwhysomepeoplearevegetar
A、Movesomesummersportstothewintersports.B、IntroducesomenewsportstotheOlympics.C、Reducesomeindoorsummersports.
最新回复
(
0
)