首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有下列程序,在横线添加; #include<iostream> using namespace std; class TestClass { public: TestClass (int n){number=n;}
有下列程序,在横线添加; #include<iostream> using namespace std; class TestClass { public: TestClass (int n){number=n;}
admin
2010-06-06
32
问题
有下列程序,在横线添加; #include<iostream> 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() { TestClsss 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/V1W0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序段:charname[20];intnun;scanf("name=%snum=%d",name,&num);当执行上述程序段,并从键盘输入:name=LiliHum=1001<回车>后,name的值为()。
若有如下形式的函数intfun(inta[],int*p,intn){……}调用函数之前需要对函数进行声明,则以下选项中错误的是()。
下列定义变量的语句中错误的是()。
有以下程序:#ineludemain(){inti=3,j=5,*p=p=&i,*q=&j,**r;r=&q;prinff(“%d,%d,%d,%d,%d\n”,i,j,*p,*q,**r);
某二叉树中度为2的结点有10个,则该二叉树中有()个叶子结点。
关于字符常量,以下叙述正确的是()。
在结构化方法中,用数据流程图(DFD)作为描述工具的软件开发阶段是()。
有以下程序:#inlude<stdio.h>main(){ints,t,A=10;doubleB=6:s=sizeof(A);t=sizeof(B);printf("%d,%d\n",s,t);}在VC6.0平台上编译运行,程序运行后的输
重载的流运算符函数应该被定义为类的【】函数。
随机试题
全身麻醉前给阿托品的目的是
符合早产儿特点的是()
简述荷马史诗的思想内容及其艺术特色。
胆道疾病的首选检查方法是
A、软坚散结B、补脾益气C、凉血止血D、清心安神E、明目女贞子除滋补肝肾外,又能
某企业2011年利润总额为1200万元,当年通过民政部门向灾区捐款200万元,当年公益性捐款应调整的应税税所得额为()。
非现场监管的内涵包括()。
对企业人员分布状况和层级结构所拟定的人员提升政策和方案的规划,这属于人力资源规划中的()。
下列关于附带认股权债券的表述中,正确的有()。
教育心理学中的认知理论改变了学习与学习者被动的观点,认为学习是一种()过程,是学生对知识的一种主动建构过程。
最新回复
(
0
)