我也有类似的情况:
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这是否意味着在传递callingFunction时必须提供passedFunction中的所有参数?这是不可能的,因为passedFunction的参数是在calledFunction中指定的
发布于 2018-05-21 12:38:45
您可以编写一个捕获兰卜达 this,在该this上可以调用passedFunction。
calledFunction([this](int v) { this->passedFunction(v); });https://stackoverflow.com/questions/50449052
复制相似问题