首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: 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
72
问题
有如下程序:
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://kaotiyun.com/show/rrAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列关于构造函数和析构函数的描述,错误的是()。
有以下程序main(){inti=10,j=1;cout<<--<<","<<++j<<endl;}执行后输出结果是
下列程序执行后的输出结果是#included<string.h>main(){chararr[2][4];strcpy(arr,"you");strepy(arr[1],"me");arr[0][3]=’&’;
一个C++程序由函数A(),B(),C()和函数P()构成,在函数A()中分别调用了函数B()和函数C(),在函数B()中调用了函数A(),且在函数P()中也调用了函数A(),则可以说
详细设计的结果基本决定了程序最终的
有如下程序:#include<iostream>usingnamespqceStd;classTestClass{private;CharC;public;TestClass(char
用树形结构来表示实体之间联系的模型称为
以下关于私有和保护成员的叙述中,不正确的是
下列语句中不是死循环的是
随机试题
简述F分布的形态特点。
下列描述错误的是
良性高血压病的特征性病变是
德国甲公司为汽车生产企业,2009年5月,甲公司拟收购丙公司的厂房和流水线并将该整体资产与境内乙国有独资公司共同投资设立中外合资经营企业,主要业务为汽车生产。德国甲公司在与乙公司、丙公司协商后,拟订投资方案和合同中有关要点如下:(1)中外合资经营企业
试论述中体西用的历史意义和局限性。
在最坏情况下
SUPPLICANT:HUMILITY::
Iwasveryinterestedin______shetoldme.
His______directionsconfusedus;wedidnotknowwhichofthetworoadstotake.
HowtoMakePeacewithYourWorkloadA)Swamped(忙碌的),underthegun,juststrugglingtostayabovewater;whateverofficecliche
最新回复
(
0
)