【发布时间】:2009-02-05 15:37:15
【问题描述】:
我需要将一个方法绑定到一个函数回调中,除非这个 sn-p 是不合法的,正如demote-boostfunction-to-a-plain-function-pointer 中所讨论的那样。
获得这种行为的最简单方法是什么?
struct C {
void m(int x) {
(void) x;
_asm int 3;
}};
typedef void (*cb_t)(int);
int main() {
C c;
boost::function<void (int x)> cb = boost::bind(&C::m, &c, _1);
cb_t raw_cb = *cb.target<cb_t>(); //null dereference
raw_cb(1);
return 0;
}
【问题讨论】:
标签: c++ boost delegates callback