C++ boost ptr_向量与unique_ptr组合时出错
我正试图从我的代码中去掉auto_ptr。但是我犯了这个错误,不知道为什么C++ boost ptr_向量与unique_ptr组合时出错,c++,c++11,boost,C++,C++11,Boost,我正试图从我的代码中去掉auto_ptr。但是我犯了这个错误,不知道为什么 调用“boost::ptr\u vector::push\u back(std::remove\u reference::type)”时没有匹配的函数 注意:候选人是: … 注意:'std::unique_ptr'不是从'std::auto_ptr'派生的。 { boost::ptr_向量&c; std::unique_ptr b(新的a(x,y)); 如果(!b->isValid()) 返回; c、 推回(标准::移动
调用“boost::ptr\u vector::push\u back(std::remove\u reference::type)”时没有匹配的函数
注意:候选人是:
…
注意:'std::unique_ptr'不是从'std::auto_ptr'派生的。
{
boost::ptr_向量&c;
std::unique_ptr b(新的a(x,y));
如果(!b->isValid())
返回;
c、 推回(标准::移动(a));
}
这正是错误消息告诉您的:boost::ptr\u vector::push\u back
需要自动\u ptr
,但您提供的唯一\u ptr
,无法转换为自动\u ptr
由于您正在转换为std::unique_ptr
,因此不再需要boost::ptr_vector
,因为它只是作为auto_ptr
的一种解决方法,无法存储在容器中。相反,使用std::vector
这正是错误消息告诉您的:boost::ptr\u vector::push\u back
需要自动ptr
,但您提供了唯一的ptr
,无法转换为自动ptr
由于您正在转换为std::unique_ptr
,因此不再需要boost::ptr_vector
,因为它只是作为auto_ptr
的一种解决方法,无法存储在容器中。写问题时请使用std::vector
查看如何显示。编写问题时,请使用预览区域查看问题的显示方式。
{
boost::ptr_vector<a>& c;
std::unique_ptr<a> b( new a(x, y) );
if (!b->isValid())
return;
c.push_back(std::move(a));
}