【发布时间】:2015-01-12 18:42:45
【问题描述】:
我正在尝试在 Visual Studio 2013 上编译以下代码:
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::make_unique 而是使用 new 时,它可以工作:
std::unique_ptr<std::thread> threadPtr;
threadPtr.reset(new std::thread([&]
{
//...
}));
我在这里做错了什么,还是编译器的问题?
【问题讨论】:
标签: c++ c++14 unique-ptr lambda