与unique_ptr相结合的升压ptr_vector错误
Error with boost ptr_vector combined with unique_ptr
我试图从我的代码中删除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));
}
这正是
错误消息告诉您的:boost::ptr_vector::push_back
期望auto_ptr
,但您提供了一个无法转换为auto_ptr
的unique_ptr
。
由于您要转换为 std::unique_ptr
,您将不再需要boost::ptr_vector
,因为它只是作为auto_ptr
的解决方法,无法存储在容器中。请改用std::vector<std::unique_ptr<T>>
.
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- std::vector的包装器,使数组的结构看起来像结构的数组
- 为什么(-1)%vector::size()总是返回0
- 在C++中将类(带有Vector成员)保存为二进制文件
- 编译器如何区分std::vector的构造函数
- 将 int 数组转换为 std::vector<int*>
- CLANG 编译器 说:变量"PTR"可能未初始化
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 在std::vector上存储带有模板的类实例
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么std::vector比数组慢
- std::vector::迭代器是否可以合法地作为指针
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 从基类ptr的vector对象中擦除