I've got a destructor in my frame class that does:
delete this->frameMatrix;
Where framematrix is of class Matrix with this as constructor and destructor:
// Constructor: Initialize matrix & sizes
Matrix::Matrix(int width, int height)
{
table = new double* [height];
for(int i = 0; i < height; i++)
table[i] = new double [width];
// Set all values to zero
for(int row = 0; row < height; row++)
{
for(int col = 0; col < width; col++)
{
table[row][col] = 0;
}
}
this->width = width;
this->height = height;
}
// Destructor: delete matrix
Matrix::~Matrix()
{
for(int row = 0; row < height; row++)
delete [] table[row];
delete [] table;
this->width = 0;
this->height = 0;
}
When calling the delete on frameMatrix the program gives an assertion failed in the destructor of matrix.
I'm I doing something wrong because I don't see the problem on how I delete the 2d double array.
EDIT:
Copy constructor:
Matrix::Matrix(const Matrix &m)
{
this->height = m.getHeight();
this->width = m.getWidth();
this->table = new double* [height];
for(int i = 0; i < height; i++)
this->table[i] = new double [width];
for(int row = 0; row < height; row++)
{
for(int col = 0; col < width; col++)
{
this->table[row][col] = m.table[row][col];
}
}
}
My overloading =
Matrix &operator = (const Matrix &m)
{
this->height = m.getHeight();
this->width = m.getWidth();
this->table = new double* [height];
for(int i = 0; i < height; i++)
this->table[i] = new double [width];
for(int row = 0; row < height; row++)
{
for(int col = 0; col < width; col++)
{
this->table[row][col] = m.table[row][col];
}
}
}