首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
TestClass类定义如下: class TestClass { private: intid; char gender; char *phone; public: TestClass():
TestClass类定义如下: class TestClass { private: intid; char gender; char *phone; public: TestClass():
admin
2013-05-30
37
问题
TestClass类定义如下:
class TestClass
{
private:
intid;
char gender;
char *phone;
public:
TestClass():id(0),gender(‘#’),phone(NULL){}
TestClass(int no,char ge=‘#’,char*ph=NULL)
{id=no;gender=ge;phone=ph;}
};
下面类对象定义语句中错误的是( )。
选项
A、TestClass myObj(1);
B、TestClass myObj(2,“11101111155”);
C、festClass myObj(1,‘m’);
D、TestClass myObj;
答案
B
解析
B)中由于有两个参数,所以其调用了第二个构造函数,第二个构造函数的两个缺省参数,在调用时,实参会按从左到右的顺序传给形参,所以第二个参数“11101111155”会传递给形参ge,而原型中的ge为字符型,实参为指向字符的指针,所以在编译时会出现错误。A)与C)都能够正确的实现参数的传递。对于D),由于在创建TestClass的实例myObj时,没有参数,所以其调用了第一个构造函数。
转载请注明原文地址:https://kaotiyun.com/show/RhNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classTest{public:Test(){n+=2;}~Test(){n-=3;}
有如下程序:#include<iostream>voidfun(int&x,inty){intt=x;x=y;y=t;}intmain(){inta[2]={23,42};
阅读下面程序:intfun2(intm){if(m%3==0)return1;elsereturn0;}voidfunl(intm,int&s){inti;for(i=1;i<m;i++)if(fun2(i))
有如下程序#include<iostream>#include<iomanip>usingnamespacestd;classMyClass{public:MyClass(){cout<<’A’;}MyClass(charc){co
有如下程序:#include<iostream.h>voidmain(){intx=1,a=0,b=0;switch(x){Case0:b++;Case1:a++;Case2:a++;b++;}cout<<"a="<<a<<","<<"
有如下函数模板声明:template<typenameT>TMax(Ta,Tb){return(a>=b)?a:b;}下列对函数模板Max()的调用中错误的是()。
有如下数组声明:intvalue[30];,下标值引用错误的是()。
软件工程研究的内容主要包括:【】技术和软件工程管理。
软件工程包括3个要素,分别为方法、工具和【】。
随机试题
文字块(Word)(写出定义、与文本的关系以及操作原则)
患者和患者授权人在手术前签《手术中快速活检患者知情同意书》的目的是
无黏性土的分类是按()
工程项目管理的核心任务是项目的()。
社会策划模式一方面强调过程的理性化,另一方面强调()。
下列有关执法为民的做法,不正确的是()。
西红柿:番茄
某种测验可以随时在网络上报名参加,某人通过这种测验的概率是.若他连续两次参加测验,则其中恰有一次通过的概率是[].
Duringrecentyearswehaveheardmuchabout"race":howthisracedoescertainthingsandthatracebelievescertainthingsand
ThedoctorsaidIwasover-weight.IfonlyI______less!
最新回复
(
0
)