[求助] 友元函数的问题
#include <iostream>
using namespace std;
//-------------------------------------------------------------------
class Boat;
class Car {
int size;
public:
void setSize (int j) { size = j; }
friend int leisure (int, const Car&, const Boat&);
};
class Boat {
int size;
public:
void setSize (int j) { size = j; }
friend int leisure (int, const Car&, const Boat&);
};
//-------------------------------------------------------------------
int main()
{
Car c1;
c1.setSize(2);
Boat b1;
b1.setSize(3);
cout << leisure (5, c1, b1);
return 0;
}
//-------------------------------------------------------------------
int leisure (int time, Car& c, Boat& b)
{
return time * c.size * b.size;
}
编译不过
不让函数leisure访问私有数据
为什么啊?