是否有方法避免使用boost::bind将成员函数附加到boost::信号槽?
我能让它工作的唯一方法是使用bind,如下所示:
mysignal.connect(boost::bind(&myClass::listenerMember, this, _1, _2));
但我真的希望它看起来更像这样:
mysignal.connect(myClass::listenerMember);
以下是一些示例代码,可以更好地展示它:
#include <iostream>
#include <cstdlib>
#include "boost/signals2.hpp"
class window
{
public:
boost::signals2::signal<void(int,int)> sigLButtonDown;
void simulateCallback(){ sigLButtonDown(1,3);}
};
class windowListener
{
public:
windowListener(window * pwindow) { pwindow->sigLButtonDown.connect(boost::bind(&windowListener::listenerMember, this, _1, _2));}
void listenerMember(int x, int y) { std::cout << "ping!" << std::endl;}
};
int main()
{
window w;
windowListener l(&w);
std::cout << "Here goes!" << std::endl;
w.simulateCallback();
}