文档库 最新最全的文档下载
当前位置:文档库 › car-boat

car-boat

car-boat

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;

}

相关文档