假设我在类中有这个公共(public)方法:
uli returnSum()
{
for_each(i, j, doSum);
return this->sum;
}
void doSum(short int y)
是同一类的私有(private)方法。我如何将它作为参数传递给 for_each?
使用上面的语法我得到 error: must
use .* or ->* to call pointer-to-member function in __f (...)'
。 this->*doSum
都不是工作。
我读到了一些关于创建指向该成员函数的指针并将其作为参数传递的内容,但我不太确定如何做到这一点。
最佳答案
你可以使用 std::bind,像这样
std::for_each(i, j, std::bind(&MyClass::doSum, this));
关于c++ - 将成员函数作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14738436/