friend class c++

The friend keyword in C++ allows a class or function to access the private and protected members of another class. When a class is declared as a friend of another class, it is given special access privileges.

Using the friend keyword:

class Class1 {
    friend class Class2;
    // ...
};

In this example, Class2 is granted access to the private and protected members of Class1.

With the friend function:

class Class1 {
    friend void function1();
    // ...
};

In this example, function1 is granted access to the private and protected members of Class1.