#include using namespace std; //Car类的定义与实现 class Boat; class Car { private: int weight; public: Car(int w) : weight(w) {} friend int getTotalWeight(Car& aCar, Boat& aBoat); }; //Boat的定义与实现 class Boat { private: int weight; public: Boat(int w) : weight(w) {} friend int getTotalWeight(Car &aCar, Boat &aBoat); }; //友元函数getTotalWeight() int getTotalWeight(Car& aCar, Boat& aBoat) { return aCar.weight + aBoat.weight; } int main() { int carWeight, boatWeight; cout << "卡车重量:"; cin >> carWeight; cout << "轮船重量:"<> boatWeight; Car myCar(carWeight); Boat myBoat(boatWeight); cout << "卡车和轮船的总重量为:" << getTotalWeight(myCar, myBoat) << endl; return 0; }