我編譯包含在Visual Studio的2015年社區異步不會調用移動構造函數在Visual Studio 2015年
auto f = async(launch::async,
&WorkerThread<Hash>::run,
WorkerThread<Hash>(mInputFile, mOutputFile),
i, numthreads, mBlockSize);
futures.push_back(std::move(f));
好了,類似的問題已經被問這裏數十次,但通常下面的代碼中的問題問題在於某處不存在std::move
。
模板類WorkerThread<Hash>
不可複製(已刪除複製構造函數和複製賦值運算符),但是可移動的。上面的代碼產生C2280: "WorkerThread<Hash>::WorkerThread(const WorkerThread<Hash> &)": attempted to reference deleted function
(這是我的翻譯)。
它似乎沒有生成移動構造函數默認情況下,這將罰款在我的情況。當我明確地將它們設置爲default
時,我得到相同的錯誤,但現在它指的是std::_Binder<std::_Unforced,_Ty,WorkerThread<Hash>,unsigned int,unsigned int,__int64>::_Binder(const std::_Binder<std::_Unforced,_Ty,WorkerThread<Hash>,unsigned int,unsigned int,__int64> &)
。
任何想法都非常受歡迎。
更新:MCVE
如果有可用的提到的編譯器,請嘗試進行編譯,並報告結果。我認爲這可能是我的一個安裝問題。
#include<future>
#include<memory>
class Foo {
public:
Foo() :mData(new int[100]) {}
void run() {}
private:
std::unique_ptr<int[]> mData;
};
int main()
{
auto f = std::async(std::launch::async, &Foo::run, Foo());
f.get();
}
你沒有發佈所有的錯誤,但我的猜測是,也許你應該使用futures.emplace_back(std :: move(f));而不是push_back? – Jonathan
@Jonathan,不,結果相同 – vehsakul
@ T.C。,Done。此代碼不適合我編譯。 – vehsakul