Rothbard
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.
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.
Sounds like the strategy pattern or a factory method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for your your very helpful comments!