1 #include<iostream>
2 class Boat;//必须事先声明
3 class Car
4 {
5 int size;
6 public:
7 void setSize(int j){size=j;}
8 int getSize(){return size;}
9 friend int leisure(int time,Car& aobj,Boat& bobj);
10 };
11 class Boat:Car//此处的Car可要可不要
12 {
13 int size;
14 public:
15 void setSize(int j){size=j;}
16 int getSize(){return size;}
17 friend int leisure(int time,Car& aobj,Boat& bobj);
18 };
19 int leisure(int time,Car& aobj,Boat& bobj)
20 {
21 return time*aobj.size*bobj.size;
22 }
23 int main()
24 {
25 Car c1;
26 c1.setSize(2);
27 Boat b1;
28 b1.setSize(3);
29 std::cout<<leisure(5,c1,b1)<<std::endl;
30 system("pause");
31 }