I have written a piece of code where I have an abstract base class. Class Tiger and Class Lion are inheriting from Animal Base Class virtually. Liger is inheriting from both Lion and Tiger. When I try to create an object of Liger and access walk function , I get the error "ambiguous access of walk". I have used virtual inheritance to avoid diamond problem. Can anyone help me to overcome this problem.
#include "stdafx.h"
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void walk() = 0;
};
class Lion : virtual public Animal
{
public:
void walk()
{
cout<<"Animal Walking"<<endl;
}
};
class Tiger : virtual public Animal
{
public:
void walk()
{
cout<<"Animal Walking"<<endl;
}
};
class Liger : public Lion , public Tiger
{
public:
};
int _tmain(int argc, _TCHAR* argv[])
{
Liger lig;
lig.walk();
return 0;
}