首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
根据输出结果填空完成下面程序。 #include<iostream.h> class Test { private: static int val; int a; public: st
根据输出结果填空完成下面程序。 #include<iostream.h> class Test { private: static int val; int a; public: st
admin
2010-12-16
18
问题
根据输出结果填空完成下面程序。
#include<iostream.h>
class Test
{
private:
static int val;
int a;
public:
static int func( );
void sfunc(Test &r);
};
______//初始化静态变量val
int Test::func( )
{
return val++;
}
void Test::sfunc(Test &r)
{
r.a=125;
cout<<"Result3="<<r.a;
}
void main( )
{
cout<<"Resultl="<<Test::func( )<<endl;
Test A;
cout<<"Result2="<<A.fune( )<<endl;
A. sfunc(A);
}
输出结果为:
Result1=201
Result2=202
Result3=125
选项
答案
int Test::val=200;
解析
类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。
转载请注明原文地址:https://jikaoti.com/ti/EHL0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){inti,j,m=55;for(i=1;i<=3;i++)for(j=3;j<=i;j++)m=m%j;printf("%d\n",m);}程序运行后的输出结果是()。
有以下程序#include<stdio.h>main(){inta,b;for(a=0;a<3;a++){scanf("%d",&b);switch(b){defau
在黑盒测试方法中,设计测试用例的主要根据是()。
fgets(str,n,fp)函数从文件中读入一个字符串,以下错误的叙述是()。
若有以下程序#include<stdio.h>char*a="you",b[]="welcome#you#to#China!";main(){inti,j=0;char*p;
设有如下定义:structsk{intm;floatx;}data,*q;若要使q指向data中的m域,正确的赋值语句是()。
表达式:(int)((double)9/2)一(9)%2的值是()。
在数据库设计中,将E-R图转换成关系数据模型的过程属于()。
设置虚基类的目的是解决二义性问题,通过用关键字【】表示虚基类。
下列哪种说法不符合多态性的含义______。
随机试题
你作为一名社区工作人员去入户调查,调查对象是一位老人,到达时发现住户家里冒出白烟。出现这个状况。你怎么处理?
电气设备检修的基本方法有哪些?
阅读郁达夫《故都的秋》中的文字:南国之秋,当然是也有它的特异的地方的,譬如廿四桥的明月,钱塘江的秋潮,普陀山的凉雾,荔枝湾的残荷等等,可是色彩不浓,回味不永。比起北国的秋来,正像是黄酒之与白干,稀饭之与馍馍,鲈鱼之与大蟹,黄犬之与骆驼。请回答:
慢波睡眠的特征包括
某女,26岁,妊娠3个月以来,按月有少量月经来潮,但胎儿生长、发育正常,不能诊断为( )
依据产品质量法,下列有关产品责任归责原则的表述中,哪些是正确的?()
从开标至工程竣工交付使用后5年时间内,业主或招标人均不得将投标人的投标资料向任何第三方泄露,除非征得原投标人的书面同意。()
下列关于基建过程中有关费用、损失和收益处理的说法中,正确的是()。
已知函数f(χ)的定义域为全体实数,则对于χ∈R,均满足f(χ+m)=(m>0).证明:函数f(χ)是周期函数.
IntheUnitedStates,campaigns【S1】______everyelectionandoftenbeginmanymonthsorevenyearsbeforetheelection.Tolaunch
最新回复
(
0
)