I am trying to store a member function from an object to call it when an appropriate event happens. Unfortunately this code gives a lot of error messages. Can anybody help me?
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;
}
This gives the following errors:
Update: with the following correction it works fine:
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;
}
One problem that I see MainPage::imageMousePressed(STObject* sender, STPointerEventArg * args)
has two arguments, but in the call to boost::bind
, you're only binding _2 to sender. That's doesn't work. You have to either bind both, or pass NULL or some sentinel value.
More generally, it looks to me like you're reinventing boost::signals