我有一个模板类,有两个模板参数,具有以下构造函数和成员:
template <class T, class TCompare>
class MyClass {
...
public:
MyClass(TCompare compare);
void addElement(T newElement);
...
};
我有一个结构体,它重载了()运算符用于整数比较:
struct IntegerLess {
bool operator () {const int& a, const int& b) {
if (a < b)
return true;
return false;
}
};
我创建了一个'MyClass'类的对象并尝试使用它:
MyClass<int, IntegerLess> myClassObject(IntegerLess());
myClassObject.addElement(10);
然而,我遇到了以下编译时错误:
error: request for member ‘addElement’ in ‘myClassObject’, which is of non-class type ‘MyClass<int, IntegerLess>(IntegerLess (*)())’
我该怎么修正它?谢谢!