《C++语言程序设计》 郑莉 P186
定义boat与car两个类,二者都有weight属性,定义二者的一个友元函数getTotalWeight(),计算二者的重量和。
#include <iostream>
using namespace std;
class Car; // class Boat 中引用了Car类的对象,所以要预先声明
class Boat
{
public:
Boat(int w) : weight(w) {
}
Boat
《C++语言程序设计》 郑莉 P186
定义boat与car两个类,二者都有weight属性,定义二者的一个友元函数getTotalWeight(),计算二者的重量和。
#include <iostream>
using namespace std;
class Car; // class Boat 中引用了Car类的对象,所以要预先声明
class Boat
{
public:
Boat(int w) : weight(w) {
}
Boat