Multiple interfaces inhertience. Casting from one to another

Posted by yossi1981 on Stack Overflow See other posts from Stack Overflow or by yossi1981
Published on 2009-06-21T09:21:06Z Indexed on 2010/05/19 5:40 UTC
Read the original article Hit count: 210

Filed under:

Consider the following set of classes/Interfaces:

class IFish{
public:
virtual void eat() = 0;
}

class IFriendly{
public:
virtual void protect() = 0;
}

class IAggresive{
public:
virtual void attack(Point inDest) = 0;
}

class CDolphin : public IFish, IFriendly{
eat...
protect....
}

class CShark : public IFish, IAggresive{
eat....
attack...
}

Now I am having the following class

void CDiver
{

Void shouldRunAway(IFish* fish)
{
//???
}

}

My question is , can "shouldRunAway" extract from the fish argument whether it is an IAggresive or IFreindly (if it is any of these at all...) is there some kind of casting that can help out?

© Stack Overflow or respective owner

Related posts about c++