有如下的程序: #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.系统不能生成默认的复制构造函数
第1题:
下面程序错误的语句是
①#include<iostream.h>
②void main()
③{
④ int * p=new int[1]
⑤ p=9
⑥ cout<<* p<<end1;
⑦ delete []p;
⑧}
A.④
B.⑤
C.⑥
D.⑦
第2题:
有如下的程序:#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); return0;}在运行上面的程序时出错,出错的原因是( )。
A.构造函数的实参不允许是本类的对象
B.没有定义实现深层复制(深拷贝)的复制构造函数
C.构造对象a时实参与形参类型不符
D.系统不能生成默认的复制构造函数
第3题:
有下列的程序: #include<cstring.h> #include<iostream.h> using namespace std; class MyString { public: MyString(const char*s); ~MyString()<delete[]data;} protected: unsigned len; char*data; };
A.构造函数的实参不允许是本类的对象
B.没有定义实现深层复制(深拷贝)的复制构造函数
C.构造对象a时实参与形参类型不符
D.系统不能生成默认的复制构造函数
第4题:
下列程序的输出结果是______。
include <iostream.h>
include <cstring.h>
using namespace std;
void fun(const char*s,char &C) {c=s[strlen (s)/2];}
int main {)
{
char str [] ="ABCDE";
char ch=str[1];
fun(str,sh);
cout<<Ch;
return 0;
}
第5题:
有以下程序: #include<string.h> #include<iostream.h> void main( ) { char * p="abcde\0fghjik\0"; cout < < strlen(p) ;} 程序运行后的输出结果是
A.12
B.15
C.6
D.5
第6题:
有以下程序 #include<string.h> #include<iostream.h> void main( ) { char*p="abcde\0fghjik\0"; cout<<strlen(p);} 程序运行后的输出结果是
A.12
B.15
C.6
D.5
第7题:
有下列的程序: #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.系统不能生成默认的复制构造函数
第8题:
有如下的程序: #include<cstring.h) #ingclude<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) {l
A.构造函数的实参不允许是本类的对象
B.没有定义实现深层复制(深拷贝)的复制构造函数
C.构造对象a时实参与形参类型不符
D.系统不能生成默认的复制构造函数
第9题:
下面程序错误的语句是
① #include<iostream.h>
② void main( )
③ {
④ int * p=new int[1] ;
⑤ p=9;
⑥ cout < < * p < <endl;
⑦ delete[ ] p;
⑧ }
A.④
B.⑤
C.⑥
D.⑦