I have a base class Shape and some other derived classes like Circle, Rectangle and so on. I would like to pass two objects to a function getDistance(object1, object2) to calculate the distance between the two objects.
My question is, how should this function be declared and implemented? Do you think I should use template since I might pass two objects from two different classes? If so, how would the template look like?
Any help is appreciated
Usually you would use a pure virtual on your base class. You already have inheritance from Shape, so templates are overkill for this problem.
Add a virtual GetPosition() to your base Shape class and make getDistance() take two Shape pointers (or references). For example:
EDIT: Pawel Zubrycki is correct – added virtual destructor on base class for good measure. 😉