2

以下のプログラムでは、メンバー関数を使用して packaged_task を作成しようとしています。

#include <future>
using namespace std;

struct S
{
    int calc(int& a)
    {
        return a*a;
    }
};

int main()
{
    S s;
    auto bnd = std::bind(&S::calc, s);
    std::packaged_task<int(int&)> task( bnd);
    return 0;
}

残念ながら、この試みはエラーになります。

これはどのように行うことができますか?

4

2 に答える 2

3

次のようなプレースホルダーを追加します。

auto bnd = std::bind(&S::calc, s, std::placeholders::_1)
于 2015-03-11T19:53:15.187 に答える