私はオンラインで見つかったこの例を実行する際にいくつか問題があります。C++スレッドとプロミス:削除された関数を参照しようとしています
void asyncFun(std::promise<int> intPromise) {
int result=5;
try {
// calculate the result
intPromise.set_value(result);
}
catch (...) {
intPromise.set_exception(std::current_exception());
}
}
int _tmain(int argc, _TCHAR* argv[]) {
std::promise<int> intPromise;
std::future<int> intFuture = intPromise.get_future();
std::thread t(asyncFun, std::move(intPromise));
std::cout << "Main thread" << std::endl;
int result = intFuture.get(); // may throw MyException
std::cout << result<<std::endl;
return 0;
}
と私は取得しています:
エラーC2280: 'STD ::約束::約束(のconst のstd ::約束&)':削除 関数cを参照しようとします: \プログラムファイル(x86の)\のMicrosoft Visualスタジオ 12.0 \ VCの\は\、機能1149年1 tryFuture
これはバグですか、使用しているVSのバージョンは? – Niall
VS 2013を使用しています。今すぐインストールしています。2015 –
[OK]をクリックします。しかし、別の回避策も 'shared_ptr'を使用しています。 – Niall