开发者

Are friends in c++ mutual? [duplicate]

This question already has answers here: Closed 12 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜