#include<iostream>
using namespace std;
class Car;
class Boat
{
friend class Car;
public:
friend int getTotalWeight(Boat &weight1,Car &weight2);
Boat(int B_weight)
{
weight1=B_weight;
}
Boat(Boat& boat1)
{
weight1=boat1.weight1;
cout <<"Calling the copy constructor"<<endl;
}
private:
int weight1;
};
class Car
{
friend class Boat;
public:
friend int getTotalWeight(Boat &weight1,Car &weight2);
Car(int C_weight)
{
weight2=C_weight;
}
Car(Car& car1)
{
weight2=car1.weight2;
cout <<"Calling the copy constructor"<<endl;
}
private:
int weight2;
};
int getTotalWeight(Boat& b,Car& c)
{
return b.weight1+c.weight2;
}
int main()
{
Boat boat1(1000);
Car car1(500);
cout<<"allweight:"<<getTotalWeight(boat1,car1)<<endl;
return 0;
}
车船总重
最新推荐文章于 2025-07-19 13:44:30 发布
3713

被折叠的 条评论
为什么被折叠?



