【发布时间】:2019-06-03 21:08:17
【问题描述】:
我想在一个类中创建一个自定义事件处理程序并传递另一个类的函数。
class EventArgs
{
};
class one
{
public:
typedef void(EventHandler)(EventArgs* e);
void RegisterFunction(EventHandler* f);
private:
list<EventHandler*>function_list;
};
class two
{
public:
two();
private:
void FunctionEvent(EventArgs* e);
};
two::two()
{
one on;
on.RegisterFunction(&FunctionEvent);
}
错误代码是: 没有匹配的函数调用'one::RegisterFunction(void (two::) EventArgs))' on.RegisterFunction(&FunctionEvent);
如果 FunctionEvent() 它不属于像这样的工作的第二类:
void FunctionEvent(EventArgs* e)
{
}
int main()
{
one on;
on.RegisterFunction(&FunctionEvent);
}
有什么区别?
【问题讨论】:
标签: c++