2015-01-12 6 views
1
내가 비주얼 스튜디오 2013에서 다음 코드를 컴파일하기 위해 노력하고있어

을 가진 make_unique 는 : 표준은 : 람다

오류와 함께 실패
std::unique_ptr<std::thread> threadPtr; 
threadPtr.reset(std::make_unique<std::thread>([&] 
{ 
    //... 

})); 

: 내가 사용으로

error C2664: 'void std::unique_ptr<std::thread,std::default_delete<_Ty>>:: 
    reset(std::thread *) throw()' : cannot convert argument 1 from 
    'std::unique_ptr<std::thread,std::default_delete<_Ty>>' to 'std::thread *' 

이 이상한 것 같다 std::make_unique 다른 곳에서는 문제가 없습니다.

std::unique_ptr<std::thread> threadPtr; 
threadPtr.reset(new std::thread([&] 
{ 
    //... 

})); 

내가 여기 뭔가 잘못하고 있는가, 또는이 컴파일러 문제 : 그러나, 나는 std::make_unique를 사용하지 않는 대신 new을 사용, 그것은 작동?

답변

5

std::make_uniquestd::unique_ptr을 반환합니다. 그러나 std::unique_ptr::reset에는 포인터가 필요합니다. 그래서 당신이 찾고있는 것은 중 하나입니다 :

std::unique_ptr<std::thread> threadPtr(std::make_unique<std::thread>([&] 
{ 
    //... 

})); 

나 :

threadPtr.reset(std::make_unique<std::thread>([&] 
{ 
    //... 

}).release()); 
+0

좋은 전화. 'threadPtr = std :: make_unique ... '를 사용할 수 있습니까? –

+0

@NicolasHolthaus 자동으로 예. –