![]() |
#2
quying2572007-11-29 13:58
|
#include<iostream>
using namespace std;
class car;
class boat
{
public:
boat(int nw=100)
{
w=nw;
}
friend int car::total(boat &p1,car &p2);
private:
int w;
};
class car
{
public:
car(int nw=50)
{
w=nw;
}
int total(boat &p1,car &p2)
{
return p1.w+p2.y ;
}
private:
int y;
};
void main()
{
boat boat1(1000);
car car1(2000);
cout<<"totalweight is"<<car1.total(boat1,car1)<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
你们帮我看看,怎么是一个类中的函数成为另一个类的友元函数调用类中的私有数据????