一道关于友元的C++题目,紧急!

来源:百度知道 编辑:UC知道 时间:2024/07/04 18:41:20
编写C++程序完成以下功能:
 定义一个Boat和Car两个类,他们都具有私用属性——重量
 编写一个函数,计算两者的重量和:
double TotalWeight(Boat& b, Car& c);
要用到友元函数

class Car;
class Boat
{public:Boat(double w){w=weight;}
double getW(){return weight;}
freind double TotalWeight(Boat& b, Car& c){return Boat.getW+Car.getW;}
private:double weight;
};
class Car
{public:Car(double w){w=weight;}
freind double TotalWeight(Boat& b, Car& c);
freind double TotalWeight(Boat& b, Car& c){return Boat.getW+Car.getW;}
private:double weight;
};

void main(void)
{Boat(100);
Car(200);
cout<<double TotalWeight(Boat& b, Car& c)<<endl;
}

==================================================================
都开学了,忘得差不多了。肯定会有错误的地方,不过希望不要错太多。也希望能帮上什么忙~