5-14 定义Boat与Cat两个类
#include
using namespace std;
class Car;
class Boat{
public:
Boat(float bweight){weight=bweight;}
friend float getTotalweight(Boat boat,Car car); private:
float weight;
};
class Car{
public:
friend float getTotalweight(Boat boat,Car car);
Car(float cweight){weight=cweight;}
private:
float weight;
};
float getTotalweight(Boat boat,Car car)
{
return boat.weight+car.weight;
}
int main()
{
Boat b(5);
Car c(4);
cout<<"the total weight is:";
cout< return 0; }