我试图从一个对象存储一个成员函数,以便在发生适当事件时调用它。不幸的是,这段代码给出了很多错误信息。有谁能够帮助我?
class MainPage
{
public:
MainPage::MainPage(void)
{
image1 = new STImagePanel("Untitled.png");
image1->OnPointerPressedHandler->add(&MainPage::imageMousePressed,this);
}
void MainPage::imageMousePressed(STObject* sender, STPointerEventArg * args)
{
MainPage * dsda = (MainPage*)this;
pres = true;
}
};
template<class SENDERTYPE, class ARG>
struct callbackInfo
{
boost::function<void(SENDERTYPE, ARG)> func;
};
template<class SENDERTYPE, class ARG>
class STEventHandler
{
public:
template<class T, class P>
void add(T x, P that)
{
//The following line gives the error
callbackInfo<SENDERTYPE,ARG> tmp { boost::bind(x,that,_2)};
functions->addLast(tmp);
}
private:
STLinkedList<callbackInfo<SENDERTYPE,ARG>>* functions;
}
这会产生以下错误:
更新:通过以下更正,它可以正常工作:
template<class T, class P>
void add(T x, P that)
{
boost::function<void(SENDERTYPE,ARG)> func(boost::bind(x,that,_1,_2));
callbackInfo<SENDERTYPE,ARG> tmp;
tmp.func = func;
}