Jump to content

  • Log In with Google      Sign In   
  • Create Account


problem with interfaces[c++]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 fatima   Members   -  Reputation: 122

Like
0Likes
Like

Posted 04 February 2012 - 06:36 AM

Hi
Please check these lines:

__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();}

};



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.

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9574

Like
0Likes
Like

Posted 04 February 2012 - 06:52 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS