首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列类的构造函数不能通过编译,正确的构造函数应该是【 】。 # inelude<iostream. h> class Sample { public: int ns const int con, Sample(int m) { con=
下列类的构造函数不能通过编译,正确的构造函数应该是【 】。 # inelude<iostream. h> class Sample { public: int ns const int con, Sample(int m) { con=
admin
2013-02-27
83
问题
下列类的构造函数不能通过编译,正确的构造函数应该是【 】。
# inelude<iostream. h>
class Sample
{
public:
int ns
const int con,
Sample(int m) { con= m+1; n= m;}
void disp() {cout<<’"normal: n="<<n<<end1; }
void disp()const {cout<<"static: n="<<n<< end1; }
};
void main()
{
const Sample a(12),
Sample b(13),
a. disp( ),
b. disp()
cout<<a, n<< "<<b. con<<end1;
}
选项
答案
Sample(int m):con(m+1){n=m;}
解析
本题考察常数据成员的初始化方法。常数据成员的定义必须出现在类体中,而且初始化只能通过构造函数的成员初始化列表进行,而且不能被更新。
转载请注明原文地址:https://www.kaotiyun.com/show/gOVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序: #include<stdio.h> main() {intx=1,y=0,a=0,b=0; switch(X) {case1: switch(y) }case0:a++;break
有以下程序 #include<stdio.h> #defineSUB(x,y)(x)*(y) main() {inta=3,b=4; printf("%d\n",SUB(a++,b++)); } 程序运行后的输出结果是(
下列关于宏的叙述中正确的是()。
有以下程序 #include<stdio.h> voidfun(intn) {staticintx[3]={1,2,3}; intk; for(k=0;k<3;k++)x[k]+=x[k]-n; for(k=0;
有以下程序: #include<stdio.h> main() { charch[]="uvwxyz",*pc;pc=ch; printf("%c\n",*(pc+5)); } 程序的运行结果是()。
设有定义:doublea[10],*s=a;,以下能够代表数组元素a[3]的是()。
某棵树中共有25个节点,且只有度为3的节点和叶子节点,其中叶子节点有7个,则该树中度为3的节点数为()。
下面概念中,不属于面向对象方法的是
有如下类声明:classMyClass{inti;private:intj;protected:intk;public:intm,n;其中,私有成员的数量为【】。
定义重载函数时,应在参数个数或参数类型上【】。
随机试题
以下关于法律和国家的关系表述正确的是()
三纲
最高人民检察院和地方各级人民检察院对已生效的裁判,如果发现确有错误,都有权按照审判监督程序提出抗诉。
患者80岁,因丹毒来诊,既往曾有左心衰病史,现心功能Ⅱ级。治疗时应注意
在生脉散中发挥"补"的作用在生脉散中发挥"清"的作用
定期存款的储户在未到期时就将存款取出,会承担利息损失。()
国家级宝物《清明上河图》展现了北宋都城东京的面貌,东京是今天的:
阅读以下说明,回答问题,将解答填入答题纸对应的解答栏内。[说明]某公司通过PLX防火墙接入Internet,网络拓扑如图13—13所示。在防火墙上利用show命令杳询当前配置信息如下:PIX#showconfignameifeth0out
Thereareasmanydefinitionsofphilosophyastherearephilosophers—perhapsthereareevenmore.Afterthreemillenniaofphil
Askpeopletonameasafeplaceandmostwillsay"home".ButeveryyeartheBritishGovernmentproducesitsofficialHomeAccid
最新回复
(
0
)