I created a Vector
class containing an array (stored in a heap) and an integer n_rows
counting the amount of elements inside the array. In order to delete the array properly during the instance destruction I used the delete
as explained here.
Class (in header file):
private:
int n_rows;
int* vect;
public:
Vector(int);
~Vector();
std::string toString(); // returns elements from vect
Destructor (in .cpp):
Vector::~Vector(){
delete [] this->vect;
cout << this->toString() << endl;
}
However if I print the array vect
after deleting it, seemingly just the first two entries get deleted.
Example:
// Vector:
[2 2 2 2 2 2]
// Destruction
[0 0 2 2 2 2]
My questions: Is this resource properly deleted? Why does it just appear that the two first elements get modified?