Your default constructor does not initialize data member matrix. So your program has undefined behaviour.
You could define the destructor and constructor the following way
Square_Matrix::Square_Matrix()
{
size = 0;
matrix = nullptr;
}
Or
Square_Matrix::Square_Matrix() : matrix( nullptr ), size( 0 )
{
}
Square_Matrix::~Square_Matrix() //causing the problem
{
if ( matrix )
{
for (int i = 0; i < size; i++){
delete [] matrix[i];
}
delete [] matrix;
}
}
Also take into account that you need either define the copy constructor and the copy assignment operator or suppress copying and assigning objects of your class.