友元函数

/////////////////////////////////////////////////////////////


#include <iostream>
using namespace std;
class Area;
class Point
{
public:
Point(int ,int);
void show(Area &);
private:
int x,y;
};
class Area
{
public :
Area(int ,int ,int );
friend void Point::show(Area &);
private:
int x,y,z;
};
void Point::show(Area &a)
{
cout<<"Point x*y : "<<x*y<<endl;
cout<<"Area x*y*z : "<<a.x*a.y*a.z<<endl;
}
Point::Point(int a,int b)
{
x = a;
y = b;
}
Area::Area(int a,int b,int c)
{
x = a;
y = b;
z = c;
}
int main()
{
Point p(40,20);
Area a(20,20,30);
p.show(a);
return 0;
}
阅读更多
换一批

没有更多推荐了,返回首页