Jump to content
  • Advertisement
Sign in to follow this  
fatima

problem with interfaces[c++]

This topic is 2508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi
Please check these lines:
[source]
__interface IAnimal
{
void Release(void);
};

__interface ICat : public IAnimal
{
void DrinkMilk(void);
};

class Animal : public IAnimal
{
public:
Animal(void){}
virtual~Animal(void){}
void Release(void){delete this;}
};

class Cat : public ICat, public Animal
{
public:
Cat(void){}
~Cat(void){}
void DrinkMilk(void){}
//void Release(void){Animal::Release();}
};
[/source]

As you see “Cat” is derived from “Animal” and “IAnimal”, so all pure virtual members of “IAnimal” are implemented. But compiler (VS 2010) says “Cat” is abstract due to “Release” method. But its defined in “Animal” and “Cat” receives it. If I uncomment the last line(in other words implement the “Release” method again), problem will be solved. Of course I don’t want to rewrite all base methods again in my derived classes.
Any Idea?
Thank you in advance.

Share this post


Link to post
Share on other sites
Advertisement
The short answer is that your Cat class implements Animal::Release(), but not ICat::Release(), and the way that you've set up your inheritance these are actually separate functions. If you want them to be the same function you need to inherit virtually from IAnimal in ICat and Animal.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!