所以我用从一个自定义的矢量容器:https://github.com/patr0nus/Vector/blob/master/Vector.h自定义矢量不支持的unique_ptr
,我试图创造的unique_ptr指针的向量自定义类对象。
它曾经失败:
error: object of type 'std::__1::unique_ptr std::__1::default_delete>' cannot be assigned because its copy assignment operator is implicitly deleted
我固定它通过添加以下代码vector.h:
void push_back(T&& val)
{
resize(m_size + 1);
m_container[m_size - 1] = std::move(val);
}
现在的问题是,我无法遍历这个矢量和其他功能,如swap
是失败:
no matching function for call to 'swap'
swap(*__x4, *__x5);
candidate template ignored: could not match 'tuple' against 'unique_ptr'
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
我需要如何解决日一些指导这些问题。
这个载体似乎是专为使用只有POD类型。 –
使用'std :: vector'是解决方案。为什么你首先需要这个定制的?这个实现的问题是绝对需要'T'是CopyConstructible,当'std :: unique_ptr'不是。 – AndyG
嗯......为什么不使用std :: vector? – mascoj