Are friends in C ++ mutual?

Possible duplicate:
Area of ​​friendship in C ++

Are there any friends in C ++?

+6
c ++ syntax
source share
2 answers
class bar { private: void barMe(); }; class foo { private: void fooMe(); friend bar; }; 

In the above example, the class foo cannot call barMe (). You must define the classes so that each other is mutual:

 class foo; // forward class bar { private: void barMe(); friend foo; }; class foo { private: void fooMe(); friend bar; }; 
+10
source share

The relationship of friends is only one way - but you have nothing to stop declaring class A as another of class B and class B as another of class A. Thus, you can establish mutual relations.

+4
source share

All Articles