首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostrcam> using namespace std; c1ass TestClass { int n; public: TestClass (int k):n(
有如下程序: #inc1ude<iostrcam> using namespace std; c1ass TestClass { int n; public: TestClass (int k):n(
admin
2017-06-19
43
问题
有如下程序:
#inc1ude<iostrcam>
using namespace std;
c1ass TestClass
{
int n;
public:
TestClass (int k):n(k){}
int get(){return n;)
int get()const {retum n+l;)
);
int main()
{
TestClass p(5);
const TestClass q(6);
cout<<p.get(F<q.get();
return 0;
}
执行后的输出结果是( )。
选项
A、55
B、57
C、75
D、77
答案
B
解析
C++中对常对象的成员函数调用,将自动调用其常成员函数’程序中调用原型为"int get()const;”的函数,对于非常对象将调用原型为"int get();。的函数。因为首先用5对对象p进行了初始化,所以执行p.get()时直接返回5,而对于常对象则以6对q进行初始化,在调用q.get0时,将调用原型为"int get()const;。的函数,该函数将返回n+l,第二个输出应为7,所以本题答案为57。
转载请注明原文地址:https://kaotiyun.com/show/yQAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下面的4个关键字中用来说明虚函数的是
类classone在声明func成员函数时发生错误,出错原因是【 】。Classone{private:inta;
有如下程序 main() {int n=9; while(n>6)<n--; cout<<n<<endl;} } 该程序段的辅出结果是
下列程序编译时发现pb->f(10);语句出现错误,其原因是【 】。#include<iostream.h>classBase{public:voidf(intx){cout<<"Base:"<<
执行语句序列charstrl[10]="ABCD",str2[10]="XYZxyz";for(inti=0;strl[i]=str2[i];i++)后,数组str1中的字符是XYZxyz,数组str2中的字符串是【 】。
重载的流运算符函数经常定义为类的______函数。
下列关于线性表叙述中,不正确的是()。
在C++程序中,如果要求通过函数来实现一种简单的功能,并且要求尽可能加快程序执行速度,则应该选用()。
在程序设计阶段应该采取________和逐步求精的方法,把一个模块的功能逐步分解,细化为一系列具体的步骤,进而用某种程序设计语言写成程序。
友元运算符。obj1>obj2被C++编译器解释为()。
随机试题
腰椎间盘突出症的辨证分型包括
悲剧的美育效果主要在于()
剧场前面的集散广场应当不小于:
地雷:手榴弹
设F1(x),F2(x)为两个分布函数,其相应的概率密度f1(x)与f2(x)是连续函数,则必为概率密度的是()
A、 B、 C、 D、 A
Endingtheconversation结束谈话
English,asacolorful,vibrantanddiversetongue,haspickedupwordsfromthemanylanguagesbywhichitsspeakershavecome
A、Itbeganassomethingbiggerbutwasnarroweddownatlast.B、Itwasbeingmuchheardof.C、Itwasaboutaquiteappealingcha
PartⅡReadingComprehension(SkimmingandScanning)Directions:Inthispart,youwillhave15minutestogooverthepassageq
最新回复
(
0
)