Possible Duplicate:
Friend scope in C++ 开发者_运维问答
Are friends in C++ mutual?
class bar
{
private:
void barMe();
};
class foo
{
private:
void fooMe();
friend bar;
};
In the above example foo class can't call barMe() You need to define the classes this way in order that the friend be mutual:
class foo; // forward
class bar
{
private:
void barMe();
friend foo;
};
class foo
{
private:
void fooMe();
friend bar;
};
The friend relationship is only one-way in general - but there is nothing to stop you declaring Class A a friend of class B AND class B a friend of class A. So a mutual relationship can be established
精彩评论