<分区>
我也有类似的情况:
class A {
void callingFunction() {
calledFunction(passedFunction);
}
void calledFunction(std::function<void(int)> foo) {
}
void passedFunction(int arguments) {
}
};
编译错误是
error: invalid use of non-static member function
如何在不使 passedFunction
静态化的情况下实现这一点?
这样做:
calledFunction(std::bind(&A::passedFunction, this);
创建此错误:
error:static assertion failed: Wrong number of arguments foor pointer-to-member
这是否意味着我必须在传递 passedFunction
时提供 callingFunction
中的所有参数?这是不可能的,因为 passedFunction
的参数在 calledFunction