Multiple inheritance and ambiguous members

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?
I learned something! Thanks.

For others, this is called the "dreaded diamond".

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 : protected virtual human { /* ... */ };
class mother : protected virtual human { /* ... */ };

class child : father, mother
{
public:
	int getA() { return a; }
};

Topic archived. No new replies allowed.