tags:

views:

110

answers:

2

Possible Duplicate:
Friend scope in C++

I am new to c++ and just wondering it!

+7  A: 
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;
};
Shay Erlichmen
Thanks for your answering and patience!
Liu
+2  A: 

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

Elemental
Thanks for your answering!
Liu