5-14
//在weight.h中 #ifndef _WEIGHT_H_ #define _WEIGHT_H_ class Car; class Boat { private: double weight; public: Boat(double w=0.0):weight(w){} double getWeight(){return weight;} friend double getTotalWeight(Car & m,Boat & n); }; class Car { private: double weight; public: Car(double w=0.0):weight(w){} double getWeight(){return weight;} friend double getTotalWeight(Car & m,Boat & n); }; #endif
1 #include<iostream> 2 #include"weight.h" 3 4 double getTotalWeight(Car & m,Boat & n) 5 { 6 double sum=0; 7 sum=m.weight+n.weight; 8 return sum; 9 } 10 11 int main() 12 { 13 Boat n(50.8); 14 Car m(40.2); 15 double s=0.0; 16 s=getTotalWeight(m,n); 17 std::cout<<"getTotalWeight"<<s<<std::endl; 18 return 0; 19 }
不要让今天成为明天的遗憾!
本文作者:Talbot3
本文链接:https://www.cnblogs.com/orangebook/p/3403772.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步