单选题 有如下程序:
#include<iostream>
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;
}
下列关于程序的描述中,正确的是______。
【正确答案】 B
【答案解析】[解析] 该题考查的是由友员函数的问题。第一句中友元函数重载应该把点号换为逗号。