0

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?

4

1 に答える 1

3

いいえ。これらの無料の関数はまったく必要なく、operator==const である必要があり、提供しない!=か、他の関係演算子を使用する必要はありません。

于 2012-11-15T12:16:40.933 に答える