您的位置:首页 > 其它

友元函数简单应用

2018-03-29 20:05 218 查看
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
int T,n,m;
class Boat{
private:
double weight;
public:
friend class Car;
Boat (double w):weight(w){};

};

class Car{
private:
double weight;
public:
Car(double w):weight(w){};
friend double totalweight(Boat &b,Car &c){
double totalWeight=b.weight+ c.weight;
return totalWeight;
}
};

int main (){
double w1,w2;
cin >>w1>>w2;
Boat boat(w1);
Car car(w2);
cout << totalweight (boat,car)<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: