[英]Error with boost ptr_vector combined with unique_ptr
I'm trying to get rid of auto_ptr from my code. 我正在尝试摆脱代码中的auto_ptr。 But im getting this error, and don't know why?
但是我得到这个错误,不知道为什么吗?
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));
}
It's exactly what the error message tells you: boost::ptr_vector::push_back
expects an auto_ptr
, but you provide a unique_ptr
, which can not be converted to auto_ptr
. 错误消息正是这样告诉您的:
boost::ptr_vector::push_back
需要一个auto_ptr
,但是您提供了unique_ptr
,无法将其转换为auto_ptr
。
Since you are converting to std::unique_ptr
, you won't need boost::ptr_vector
any more, since it was only meant as a workaround for auto_ptr
, which could not be stored in containers. 由于您要转换为
std::unique_ptr
,因此不再需要boost::ptr_vector
,因为这仅是auto_ptr
的解决方法,该方法无法存储在容器中。 Instead use std::vector<std::unique_ptr<T>>
. 而是使用
std::vector<std::unique_ptr<T>>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.