首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: using namespace std; class Boat; class Car{ public: Car(int i):weight(i){} friend int Total(const Car &c,const Boat&b);//
有如下程序: using namespace std; class Boat; class Car{ public: Car(int i):weight(i){} friend int Total(const Car &c,const Boat&b);//
admin
2018-12-04
45
问题
有如下程序:
using namespace std;
class Boat;
class Car{
public:
Car(int i):weight(i){}
friend int Total(const Car &c,const Boat&b);////①
private:
int weight;
};
class Boat{
public:
Boat(int i):weight(i){}
friend int Total(const Car&c,const Boat &b);
private:
int weight;
};
int Total(const Car &c,const Boat &b){//②
return c.weight+b.weight;
}
int main(){
Car c(10);
Boat b(8);
cout<<"The total weight is"<<Total(c,b)<<endl;//③
return 0:
}
下列关于程序的描述中,正确的是( )。
选项
A、程序编译正确
B、程序编译时语句①出错
C、程序编译时语句②出错
D、程序编译时语句③出错
答案
A
解析
程序中定义了类Car和类Boat,在两个类中分别定义他们的构造函数和友元函数friend。程序在VC6.0中编译通过。
转载请注明原文地址:https://jikaoti.com/ti/VVt0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列关于构造函数和析构函数的描述,错误的是()。
下面关于break语句的描述中,不正确的是()。
下面程序编译时发现ma[3]=9错误,其原因是______。#include<iostream.h>classFunArray{int*pa;//指向一个数组空问intsize;//数组元素个
通常,将软件产品从提出、实现、使用维护到停止使用退役的过程称为______。
顺序存储方法是把逻辑上相邻的结点存储在物理位置______的存储单元中。
有以下程序:#include<iostream>usingnamespacestd;classA{private:inta;public:A(inti){a=i;}void
下面是一个栈类的模板,其中push函数将元素i压入栈顶,pop函数弹出栈顶元素栈初始为空,top值为0,栈项元素在stack[top-]中,在下面横线处填上适当语句,完成栈类模板的定义。template<classT>classTstack{
下列关于this指针的叙述中,正确的是()。
将以下程序写成三日运算表达式是_____。if(a>b)max=a;elsemax=b;
随机试题
下列不属于企业战略特征的是()。
《石崇与王恺争豪》选自()
物质循环又称为生物地球化学循环,是指各种化学物质在生物和______之间的循环运转。
脾阳不足阳虚失摄之便血,宜选用风热客于肠中,损伤脉络之便血,宜选用
A.午后热甚B.口干舌燥C.头胀身重D.小便不利E.脉象沉涩上焦病证的临床表现,多见
除有关节肿痛外,对类风湿关节炎诊断最有意义的表现是
“申报日期”栏:()。“集装箱号”栏:()。
儿童能区分桔子和橙子,其使用的感知觉是()
SinceHenryFordturneditintoamass-marketproductacenturyago,thecarhasdeliveredmanybenefits.Ithas【C1】______econom
MySQL数据库备份与恢复的常用方法有哪些?
最新回复
(
0
)