I have recently learned in school about the dreaded diamond.And I wrote a program using virtual inheritance to overcome the problems.I use g++ and I have the following errors with this program,
//doing to create an illustration for dreaded diamond
#include<iostream>
using namespace std;
class vehicle
{
public:
virtual void move()
{
cout<<"\n\nme moves";
}
};
class car :public virtual vehicle
{
public:
virtual void move()
{
cout<<"\n\ni move on the road with screeching speed";
}
};
class boat :public virtual vehicle
{
public:
virtual void move()
{
cout<<"\n\ni move on water";
}
};
class watercar :public car,boat
{
public:
void go()
{
cout<<"\n\nI move on water or road based on your preference";
}
};
int main()
{
watercar obj;
int a;
obj.go();
cin>>a;
if(a==1)
obj.move();
else if(a==0)
obj.move();
return 0;
}
errors:
dreaded_diamond.cc:29: error: no unique final overrider for ‘virtual void vehicle::move()’ in ‘watercar’
dreaded_diamond.cc: In function ‘int main()’:
dreaded_diamond.cc:43: error: request for member ‘move’ is ambiguous
dreaded_diamond.cc:23: error: candidates are: virtual void boat::move()
dreaded_diamond.cc:15: error: virtual void car::move()
dreaded_diamond.cc:45: error: request for member ‘move’ is ambiguous
dreaded_diamond.cc:23: error: candidates are: virtual void boat::move()
dreaded_diamond.cc:15: error: virtual void car::move()
please help me
thanx in advance...