For the following code, does anyone understand how and why the friend function is working? what is emp and why does emp.boss point to name?? The purpose was the create a class that adds employees to subteams.• Since employees can have only one boss, if we hire someone who already has a boss, we should report a failure.
#include<iostream>.
#include<string>
#include<vector>
class Employee{
friend ostream& operator<<(ostream& os, const Employee& emp){
    cout<< "Name: "<< emp.name << endl;
    cout<< "Boss: ";
    if (emp.boss != nullptr){
        cout<< emp.boss -> name << endl;
    }
    else
    {
        cout << "I am the boss." <<endl;
    }
    cout<< "Team ..." <<endl;
    for(fize_t i = 0; i < emp.myTeam.size(); i++) {
        cout << "\t" << emp.myTeam[i] -> name << endl;
    }
    return os;
}
private:
    string name;
    Employee* boss;
    vector<Employee*> myTeam;
public:
    Employee(const string& name, Employee* boss = nullptr): name(name),    boss(boss)
//
    {
    if(boss != nullptr){
        boss -> myTeam.push_back(this);
    }
}
//condition check
bool addToTeam(Employee& newGuy)
{
    if(newGuy.boss != nullptr)
    {
        return False;
    }
    newGuy.boss = this;
    myTeam.push_back(&newGuy);
    return true;
}
bool removeFromTeam(Employee& emp)
{
    for(size_t i=0; i <myTeam.size(); i++)
    {
        if(myTeam[i] == &emp) //the first item in the vector is the reference to &emp, so now the first item is now the address of the employee?        {
            emp.boss = nullptr;
            myTeam[i] = myTeam[myTeam.size() -1];
            myTeam.pop_back();
            return true;
        }
    }
    return false;
    }
};
I tried to get the correct code.
 
     
    