1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include<iostream>
using
namespace
std;
class
Boat{
public
:
Boat(
int
Weight){
weight1=Weight;
}
Boat(Boat &p){
weight1=p.weight1;
}
friend
class
Car;
private
:
int
weight1;
};
class
Car{
public
:
Car(
int
Weight,Boat p){
weight1=p.weight1;
weight2=Weight;
}
int
getTotalWeight(){
return
weight1+weight2;
}
private
:
int
weight1,weight2;
};
int
main(){
Boat myboat(100);
Car mycar(200,myboat);
cout<<
"The total weight is "
<<mycar.getTotalWeight()<<endl;
return
0;
}
|
本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1338338,如需转载请自行联系原作者