我有属性的类向量:删除浅的复制对象和原始对象
class Vector
{
private:
int _capacity;
int _size;
int _resizeFactor;
int* _elements;
用这种方法:
Vector::Vector(const Vector& other)
{
this->_size = other._size;
this->_capacity = other._capacity;
this->_resizeFactor = other._resizeFactor;
delete[] this->_elements;
this->_elements = other._elements;
}
这个析构函数:
Vector::~Vector()
{
if (this->_elements)
delete[] this->_elements;
this->_elements = NULL;
}
后声明对象,将数组插入并复制它,在程序结束时出现错误:
1.exe has triggered a breakpoint.
that points to the line:
delete[] this->_elements;
in the destructor.
我怎样才能取消销毁只有1个对象? 不改变属性类型
你有没有考虑使用'标准:: shared_ptr'? – Arash
您为什么使用'这 - >' –
如果我正确理解,不具有效果 – arik