|
-
January 18th, 2016, 08:16 PM
#1
hierarchy of abstract interfaces implementation
Hello,
I have a hierarchy of abstract interfaces to be used by an other api. For exemple:
//*******************
#include <iostream>
using namespace std;
class AnimalInterface
{
public:
virtual ~AnimalInterface() = 0;
virtual void eat () = 0;
};
AnimalInterface::~AnimalInterface()
{}
class BirdInterface : public AnimalInterface
{
public:
virtual ~BirdInterface() = 0;
virtual void fly() = 0;
};
BirdInterface::~BirdInterface()
{
}
class Animal : public AnimalInterface
{
public:
void eat () { cout << "miam miam..." << endl;};
};
class Bird : public BirdInterface, public Animal
{
public:
void fly() { cout << "flap flap flap ..." << endl;};
void eat () { Animal::eat(); } ;
};
int main(int argc, char **argv) {
Bird bird;
bird.eat();
bird.fly();
}
//*******************
I have a problem with the method Bird::eat, it requires to explicitly calls the ancestor Animal::eat method. It becomes complicated to recall the ancestor methods for descendent classes when the hierarchy increases in size.
Do you know a way to avoid this kind of repetitions or something that would mean the class Bird implements the AnimalInterface through the Animal class.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|