我想知道是否可以将2个成员函数与“ void * ,但这也不起作用。
template <class Receiver, class Sender>
class CallBack2 : public ICallBack2 {
protected:
Receiver* receiver;
void(Receiver::*function)(Sender*);
Sender* sender;
public:
CallBack2(Receiver* _receiver, void(Receiver::*_function)(Sender*), Sender* _sender) : receiver(_receiver), function(_function), sender(_sender) {};
virtual ~CallBack2() {};
virtual void callBack() {
(receiver->*function)(sender);
}
virtual bool operator<(const ICallBack2* _other) const {
CallBack2<Receiver, Sender>* other = (CallBack2<Receiver, Sender>*)_other;
if (receiver < other->receiver) {
return true;
} else if (receiver == other->receiver && function < other->function) {
return true; // this line gives the error
}
return false;
}
};
有什么想法吗?
最佳答案
如果您只想随意将它们作为集合/映射中的键,则可以对其进行reinterpret_cast
。您可能需要像exact_int<sizeof(void (Foo::*bar)())>::type
这样的模板类,因为pointers to member functions can have funny sizes。
关于c++ - 成员函数可以通过哪些方式相互比较?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6662917/