recursive friend classes

后端 未结 4 1896
情深已故
情深已故 2021-01-17 22:03

Is there any way around this:

class B;

class C { 
 public:
  C() { }
 private:
  int i;
  friend B::B();
};

class B { 
 public:
  B() { }
 private:
  int i         


        
4条回答
  •  甜味超标
    2021-01-17 22:46

    According to IBM's documentation (which I realize is not normative):

    A class Y must be defined before any member of Y can be declared a friend of another class.

    So I think the answer is "no".

    Of course, you can use

    friend class B;
    

    ...instead of friend B::B(), but that grants friendship to all of B's members. And you probably already knew that.

提交回复
热议问题