首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下的程序: #include <cstring.h> #include <iostream.h> using namespace std; class MyString { public: MyString
有如下的程序: #include <cstring.h> #include <iostream.h> using namespace std; class MyString { public: MyString
admin
2013-02-27
116
问题
有如下的程序: #include <cstring.h> #include <iostream.h> using namespace std; class MyString { public: MyString(const char*s); ~MyString () {delete [] data;} protected: unsigned len; char*data; }; MyString::MyString(const char *s) { len=strlen (s); data=new char[len+1]; strcpy (data,s); } int main () { MyString a("C++ Programing"); MyString b(a); return 0; } 在运行上面的程序时出错,出错的原因是
选项
A、构造函数的实参不允许是本类的对象
B、没有定义实现深层复制(深拷贝)的复制构造函数
C、构造对象a时实参与形参类型不符
D、系统不能生成默认的复制构造函数
答案
B
解析
本题考核类的构造函数。c++语言中当一个新对象被另一个已存在的同类型对象初始化时要调用复制构造函数,语句"MyString b(a);"符合此条件将调用类MyString的复制构造函数,但是类MyString没有定义此复制构造函数,所以会出错。
转载请注明原文地址:https://kaotiyun.com/show/2dVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有下列程序 #include<stdio.h> main() { char*P="6938"; inti,s=0; for(i=3;i>=0;i--) s=10*s+p[i]-’0’; printf("
有以下程序 #include<stdio.h> main() {charch=’D’; while(ch>’A’) {ch--; putchar(ch); if(ch==’A’)break; putchar(ch+1);
有以下程序: #include<stdio.h> main() {inty=10; while(y--); printf("y=%d\n",y); } 程序执行后的输出结果是()。
下列数据流图构造规则中正确的是()。
下列各组排序法中,最坏情况下比较次数相同的是()。
下列叙述中正确的是()。
有以下程序: #include<stdio.h> main() {intx=1,y=0,a=0,b=0; switch(X) {case1: switch(y) }case0:a++;break
给定程序MODl1.C中函数char*fun(char*s1,char*s2,char*r)的功能:将两个长度相等的数字字符串当作两个加数,求其代表的数值之和并以字符串的形式存入r所指内存且返回。例如:s1是”723”,s2是”567”
关于new运算符的下列描述中,错误的是()。
已知一棵二叉树前序遍历和中序遍历分别为ABDEGCFH和DBGEACHF,则该二叉树的后序遍历为
随机试题
下列不属于人工主动免疫生物制品的是
普通股票股东拥有()直接体现了其在经济利益上的要求。
法国和德国是两个宿怨深厚的邻居。在二战以前的1100多年中,他们一共打了200多场战争.平均5年就开战一次。历史给这两个持续对抗了几个世纪的国家两败俱伤的惨痛教训,也启迪了它们“相逢一笑泯恩仇”的政治智慧。这种“政治智慧”是()。
()对于长河落日圆相当于山峦对于()
设随机变量X的分布律为P{X=k)=p(1-p)k-1(k=1,2,…),Y在1~k之间等可能取值,求P{Y=3).
InJanuary2002,duringthefirstweeksofasix-monthstayattheChildren’sHospitalofPhiladelphiaforleukemia(白血病)treatm
PresidentCoolidge’sstatement,“ThebusinessofAmericaisbusiness,”stillpointstoanimportanttruthtodaythatbusinessin
Ilikedlettersonwhichtheirhandwritingwasrushedandslightlyillegible,becauseifIhadtroubledecipheringthehandwriti
A、Hewasinhispuberty.B、Hewasinhischildhood.C、Hewasinhismiddleage.D、Hewasinhissixties.B
A、Eightbillionaireshavemoremoneythan3.6billionthepoorestpeople.B、Eightbillionaireshaveasmuchmoneyas3.6billi
最新回复
(
0
)