67
以下代码会导致cl.exe崩溃(MS VS2005)。
我想使用升压绑定来创建一个函数来调用一个MyClass的的方法:如何在成员函数中使用boost绑定
#include "stdafx.h"
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <functional>
class myclass {
public:
void fun1() { printf("fun1()\n"); }
void fun2(int i) { printf("fun2(%d)\n", i); }
void testit() {
boost::function<void()> f1(boost::bind(&myclass::fun1, this));
boost::function<void (int)> f2(boost::bind(&myclass::fun2, this)); //fails
f1();
f2(111);
}
};
int main(int argc, char* argv[]) {
myclass mc;
mc.testit();
return 0;
}
我在做什么错?
任何机会,你可以帮助这个http://stackoverflow.com/questions/13074756/how-to-avoid-static-member-function-when-using-gsl-with-c?它是相似的,但'std :: function'给出了一个错误 – 2012-10-29 04:28:22
谢谢,这有点令人困惑,但你的答案拯救了我的培根! – portforwardpodcast 2014-06-20 02:28:11