在我的C ++代码中,我编写了两个函子,可以将它们用作函数的参数。像这样:
template<class T>
class MyGreater{
public:
bool operator()(const T &value1, const T &value2) {
return value1 > value2;
}
};
template<class T>
class MyEquall{
public:
bool operator()(const T &value1, const T &value2) {
return value1 == value2;
}
};
But now I am looking to write like 4 other to cover all of these: <,<=,>,>=,==,!=
does that mean I need to write 4 different classes for everyone?
重要说明:我知道我可以使用std :: Greater等,但是我的教授不允许这样做,并告诉我们编写自己的代码。
我正在使用C ++ 11并想坚持使用函子