【发布时间】:2016-02-24 05:59:50
【问题描述】:
我正在使用 std::bind 在 lambda 函数中绑定一个成员函数,代码如下:
class A {
...
...
public:
foo(function<void()> f) {
}
...
...
};
class B {
...
...
A a;
public:
B_function_1(){
a.foo([](){
some_other_function(bind(&B::B_function_2, this, _1,_2));
}
...
private:
B_function_2(arg1, arg2) {
...
}
};
我的问题是当我尝试编译时出现此错误:
error: ‘this’ was not captured for this lambda function
在我的例子中,这是指当前类(B 类)。 所以,我的问题是这里有什么问题?我错过了什么?
谢谢。
【问题讨论】:
-
错误信息就在那里说。
this未被捕获。你需要捕捉它。