c++编程求解(简单的)

来源:百度知道 编辑:UC知道 时间:2024/06/04 00:36:09
定义boat和car两个类,二者都有weight属性,定义二者的一个友元函数同他列为搞糊涂(),计算重量和。

//------------------------------------------------------------------------------
// Copyright (c) 2009 eryar All rights reserved.
//
// File : Main.cpp
// Author : eryar@163.com
// Date : 2009-10-16 1:20
// Version : 1.0v
//
// Description : 定义boat和car两个类,二者都有weight属性,定义二者的一个友元函数
// 计算重量和
//
//==============================================================================

#include <iostream>
using namespace std;

class Boat;

class Car{
public:
void Set(int w) { weight = w; }
friend int TotalWeight(const Car& car, const Boat& boat);
private:
int weight;
};

class Boat{
public:
void Set(int w) { weight = w; }
friend int TotalWeight(const Car& car, const Boat& boat);
private:
int weight;
};

int TotalWeight(const C