If I have a series of inherited classes like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class human
{
protected:
int a;
};
class father : protected human { /* ... */ };
class mother : protected human { /* ... */ };
class child : father, mother
{
public:
int getA() { return a; }
};
In line 13 we see "Error: 'child::a' is ambiguous". I understand why it happens, but what is the best way to get around this?
The solution is to ensure that only one of the base classes (human in this case) is created.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class human
{
protected:
int a;
};
class father : protectedvirtual human { /* ... */ };
class mother : protectedvirtual human { /* ... */ };
class child : father, mother
{
public:
int getA() { return a; }
};