成员字段的成员函数上的std :: async

gal*_*h92 0 c++ c++11

class Foo
{

private:

    std::unique_ptr<Bar>& bar;
    int retVal;
    std::future<int> myFuture = std::async(std::launch::async, &Foo::bar->myMethod, this);

    Foo(std::unique_ptr<Bar>& bar_) : bar(bar_) {}

}
Run Code Online (Sandbox Code Playgroud)

我相信这总结了这个话题,因为这不起作用.我怎样才能推出myFutureBar::myMethod

Cal*_*eth 6

你需要命名Bar::myMethod,并传递(适当的cv)Bar *Bar &.这看起来像

std::async(std::launch::async, &Bar::myMethod, bar.get());
Run Code Online (Sandbox Code Playgroud)