S
S
Sazoks2019-04-19 10:48:41
OOP
Sazoks, 2019-04-19 10:48:41

How to make 2 classes friendly to each other (C++)?

Hello. There are two classes. It is necessary to make them friendly TO EACH OTHER.
As I understand it, in order to make class A friendly to class B, the compiler must FULLY see class A, and not just its prototype. But I need to make 2 classes "mutual friendly".
Code model:

class A;

class B
{
friend class A;
private:
int x;
public:
B(int x) {this->x = x;}
}

class A
{
friend class B;
private: 
int x;
public:
A(int x) {this->x = x;}
}

Actually, that's all.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question