I have a weird problem with destructors. My code works in older machines with g++-2.95, g++-3.3, g++-4.0, g++-4.0.1 and not in my machine with g++-4.4.1. Do you know why? Here I show a small example that reproduces the error (in my machine):
#include <iostream>
class Matrix{
public:
Matrix(){};
Matrix(int nin);
~Matrix();
int Set();
private:
int n;
double * data;
};
Matrix::Matrix(int nin){
n = nin;
data = new double[n];
std::cout << "Constructor " << data << std::endl;
}
Matrix::~Matrix(){
std::cout << "Destructor " << data << std::endl;
delete [] data; data = NULL;
std::cout << "End destructor " << data << std::endl;
}
int Matrix::Set(){
for (int i=0;i<n;i++){
data[i*n+i] = 1.;
}
}
int main(){
Matrix A(50);
A.Set();
std::cout << "Finished normally" << std::endl;
}
Thanks in advance