I have a class that contains the following virtual method:
struct point {
template<typename T>
virtual typename std::enable_if<std::is_base_of<point, T>::value, double>::type distTo(T &other) const = 0;
};
The above doesn't work because:
error: templates may not be ‘virtual’
The plan is to specialize the class by making more specific instances of it like point2D
, point3D
. However, I only want the function to work with types of the same class. So if point2D
where to inherit this class, the method distTo
should only take parameter of type point2D
. How can I accomplish this?
This is what I had tried before I did the above:
virtual double distTo(point& other) = 0;
But when I override this method in the point2D
class and try to replace the parameter with one of type point2D
, I run into compiler errors.
Thanks for your time