Why cannot I privately derive a class from both a class and another class that the class being derived from uses as a base. So, I have the the following
class Money
{
public:
void get() {std::cin >> amount;}
private:
float amount;
}
class Employee
{
public:
void get() {std::cin >> lastName;}
private:
std::string lastName;
}
class Manager : public Employee, private Money //money is used to store a wage
{
public:
void get() {Employee::get(); Money::get();}
}
class Executive : public Manager, private Money // money is used to store additional bonuses
//warning :direct base 'Money' inaccessible in 'Executive' due to ambiguity
{
public:
void get() {Manager::get(); Money::get();}
}
I expected that in the Executive
class Manager::get()
would invoke Money::get()
to save a wage, while the other Money::get()
would save the additional bonuses.
As far as I know for now, private inheritance may be applied as a form of composition or when the base's interface should be hidden from outsiders, but is useful in implementing the class being derived. I undestand that in this particular case composition is all I need, still, I cannot understand what kind of ambiguity the compiler warns me about, for private inheritance does not allow neither outside classes nor subclasses of a privately derived class to take advantage of the relation