Link to home
Start Free TrialLog in
Avatar of Rothbard
RothbardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Function overloading and inheritance in C++

Suppose I have classes Bulldog and Labrador which publically derive from base class Dog, and I have a function, e.g. a method of a different class, called reward, and I want it to produce different results for objects of class Dog and Bulldog, or for objects of class Bulldog and Labrador. What is the best way of doing this for a C++ developer?

I understand that if Dog has any virtual functions, then I can use dynamic_cast for this purpose. Is that something you would recommend? If not, what do you think would be the best approach?

Thanks.
Avatar of ste5an
ste5an
Flag of Germany image

Sounds like the strategy pattern or a factory method.
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rothbard

ASKER

Many thanks for your your very helpful comments!