IamMan
IamMan

Reputation: 442

How to declare a friend that is a member function of another not yet defined class in C++?

How I declare B's constructor to be a friend of A? I tried:

class A
{
  private:
   A();
  public:
   friend B::B();
};

class B
{
  public:
    B();
};

Upvotes: 5

Views: 789

Answers (1)

Alexey Malistov
Alexey Malistov

Reputation: 26975

replace B:: with class;

class A
{
private:
    A();
public:
   friend class B;
};

class B
{
public:
    B();
};

Upvotes: 7

Related Questions