is this a good example to demonstrate the different types of inheritance?
kindly give feed back and suggestions..
ps:using the g++ compiler
#include<iostream>
using namespace std;
class life{
public:
virtual void eats()=0;
protected:
char* predator; char* prey;
};
class producers : public life{
virtual void eats()=0;
};
class animal : public life{
virtual void eats()=0;
};
class plants : public producers{
public:
void eats();
plants();
};
class carni : public animal{
public:
void eats();
carni();
};
class herbi : public animal{
public:
void eats();
herbi();
};
class omni : virtual public carni, virtual public herbi{
public:
void eats();
omni();
};
class decomps :virtual public omni, virtual public plants{
public:
void eats();
decomps();
};
carni :: carni(){
predator="tiger";
prey="deer";
}
void carni :: eats(){
cout<<predator<<" eat "<<prey<<endl;
}
herbi :: herbi(){
predator="deer";
prey="Plants";
}
void herbi :: eats(){
cout<<predator<<" eat "<<prey<<endl;
}
plants :: plants(){
predator="plants";
prey="sun light";
}
void plants :: eats(){
cout<<predator<<" uses "<<prey<<endl;
}
omni :: omni(){
herbi::predator="Man";
carni::predator="Man";
}
void omni :: eats(){
herbi::eats();
cout<<"and ";
carni::eats();
}
decomps :: decomps(){
plants::predator="Algae & Fungi";
plants::prey="dead plants";
omni::carni::predator="Algae & Fungi";
omni::carni::prey="Dead Animals";
}
void decomps :: eats(){
cout<<plants::predator<<" decomposes "<<plants::prey<<endl;
cout<<"and ";
cout<<omni::carni::predator<<" decomposes "<<omni::carni::prey<<endl;
}
int main(){
life* c;
carni c1;
c=&c1;
c->eats();
herbi h1;
c=&h1;
c->eats();
plants p;
c=&p;
c->eats();
omni o;
o.eats();
decomps d;
d.eats();
system("pause");
return 0;
}