我正试图从我的代码中删除auto_ptr.但我得到这个错误,不知道为什么?
no matching function for call to 'boost::ptr_vector<a>::push_back(std::remove_reference<std::unique_ptr<a>&>::type)'
note: candidates are:
...
note: 'std::unique_ptr<a>' is not derived from 'std::auto_ptr<T>'
{
boost::ptr_vector<a>& c;
std::unique_ptr<a> b( new a(x, y) );
if (!b->isValid())
return;
c.push_back(std::move(a));
}
Run Code Online (Sandbox Code Playgroud)
这正是错误消息告诉您的内容:boost::ptr_vector::push_back期望一个auto_ptr,但是您提供的unique_ptr,无法转换为auto_ptr.
由于您要转换为std::unique_ptr,boost::ptr_vector因此它不再需要,因为它仅用作解决方法auto_ptr,无法存储在容器中.而是使用std::vector<std::unique_ptr<T>>.