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 }

 

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-05-28
  • 2022-12-23
  • 2021-05-25
  • 2021-06-02
  • 2021-07-27
  • 2021-08-03
猜你喜欢
  • 2021-06-30
  • 2021-09-19
  • 2022-12-23
  • 2021-07-30
  • 2021-05-07
  • 2022-12-23
  • 2021-11-16
相关资源
相似解决方案