One thing doesn't make sense. We're not talking about the salary, but the cost of an employee to the company. The employee class should not have the getMyCostToCompany member, because no employee should be aware of their coworkers' wages.
Therefore there should be another class (Company), which has an array of workers and also the method to find everyone's cost. The employee could be its friend (the company should know everything about the worker).
Then you could use a recursive function to return everyone's cost.
(It would also make sense if each boss actually kept a list of all people working directly under them. Now you'd have to loop through all the workers of the company - probably several times.)
So here is what I would do (using strings instead of char arrays)
Code:
class Company;
class Employee
{
private:
std::string name, bossname;
float salary;
bool isBoss;
friend class Company;
public:
Employee(std::string x, std::string y, float n, bool a):
name(x), bossname(y), salary(n), isBoss(a) {}
};
class Company
{
private:
std::vector<Employee> v;
public:
void addEmployee(Employee e) {v.push_back(e);}
float getCost(Employee& s)
{
float result = s.salary;
if (s.isBoss)
for (int i = 0; i < v.size(); i++)
if (v[i].bossname == s.name)
result += getCost(v[i]);
return result;
}
};