/*友元函数可以访问类中的私有成员,定义在类中,但是不属于类*/
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class point
{
public:
void setLineX(int x);
friend void printPoint(point tmpPoint);
private:
int xPoint;
};
void point::setLineX(int x)
{
xPoint = x;
}
void printPoint(point tmpPoint)
{
cout<<"xPoint: "<<tmpPoint.xPoint<<endl;
}
int main()
{
point xPoint;
xPoint.setLineX(5);
printPoint(xPoint);
return 0;
}
友元函数声明在类中