Question

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();
};
Was it helpful?

Solution

replace B:: with class;

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

class B
{
public:
    B();
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top