友元类
2013-12-09 13:57
218 查看
#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; }
相关文章推荐