friend function in C++

A friend function is a non-member function that helps to access private and protected data. This function is not part of the class but must be declared within the class so that it can access the private and protected data. 
A friend function can be: 
* A member function of another class 
* A global function 
```
#include <iostream>
using namespace std;

class B;

class A {
public:
    A() {}
    B createB();
};

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

B A::createB() {
    cout<<"create B"<<endl;
    return B();
}

int main() {
    B b = A().createB();
}
```