Reputation: 1133
I would like to know how can I combine the a template function to a class. In order to the sorting of the classes. Here are the codes.
Template.h
template<typename T>
bool lessThan(T t1, T t2) {
bool result = false;
if (t1 < t2) {
result = !result;
}
return result;
}
template<typename T>
bool greaterThan(T t1, T t2) {
bool result = false;
if (t1 > t2) {
result = !result;
}
return result;
}
Point.h
//Operator Overloading
Point2D operator-(Point2D);
bool operator<(const Point2D& p2d)const;
bool operator>(const Point2D& p2d)const;
bool operator==(Point2D);
Is this correct?
Upvotes: 0
Views: 67
Reputation: 146940
No. There's absolutely no need whatsoever for those free functions, and operator==
should be const, and you don't provide !=
or some other relational operators.
Upvotes: 3