友元成员函数无法访问类的private数据成员,这是怎么回事?
#ifndef COORDINATE_H
#define COORDINATE_H
#include<iostream>
#include"Circle.h"
using namespace std;
class Coordinate
{
friend void Circle::printMember(Coordinate &coor);
public:
Coordinate(int x,int y)
{
m_iX = x;
m_iY = y;
cout << "Coordinate(int x,int y)" << endl;
}
~Coordinate()
{
cout << "~Coordinate" << endl;
}
private:
int m_iX;
int m_iY;
};
#endif
#ifndef CIRCLE_H
#define CIRCLE_H
#include <iostream>
#include"Coordinate.h"
using namespace std;
class Coordinate;
class Circle
{
public:
void printMember(Coordinate &coor)
{
cout << coor.m_iX << "," << coor.m_iY << endl;
}
};
#endif
#include"Coordinate.h"
#include"Circle.h"
#include<iostream>
using namespace std;
int main()
{
Coordinate coor(4,5);
Circle c;
c.printMember(coor);
system("pause");
return 0;
}