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 中国大陆许可协议进行许可。

posted @   Talbot3  阅读(200)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.