H
Huibuh
In one of my header-files I have a class named "matrix" with the function to
construct a matrix. It works properly but at the time of destruction of the
class the program stops. What have I done wrong? Thanks in advance Dieter
class matrix
{
public:
matrix* next;
int xDim;
int yDim;
int **field;
~ matrix()
{
for (int line=0; line<xDim; line++)
delete [] field[line];
delete [] field;
// delete next;
};
matrix::matrix(int x, int y)
{
int i, j;
xDim=x;
yDim=y;
field = new int* [xDim];
for(i=0; i<xDim; i++)
field = new int [yDim];
for(i=0; i<xDim; i++)
for(j=0; j<yDim; j++)
field[j]=INT_MAX;
}
void Setnext (matrix* ne) {next=ne;}
matrix* Getnext () {return next;}
void Setmatrix (int Lines, int Splits, int w)
{
field[Lines][Splits]=w;
}
int Getmatrix (int Lines, int Splits)
{
return field[Lines][Splits];
}
};
construct a matrix. It works properly but at the time of destruction of the
class the program stops. What have I done wrong? Thanks in advance Dieter
class matrix
{
public:
matrix* next;
int xDim;
int yDim;
int **field;
~ matrix()
{
for (int line=0; line<xDim; line++)
delete [] field[line];
delete [] field;
// delete next;
};
matrix::matrix(int x, int y)
{
int i, j;
xDim=x;
yDim=y;
field = new int* [xDim];
for(i=0; i<xDim; i++)
field = new int [yDim];
for(i=0; i<xDim; i++)
for(j=0; j<yDim; j++)
field[j]=INT_MAX;
}
void Setnext (matrix* ne) {next=ne;}
matrix* Getnext () {return next;}
void Setmatrix (int Lines, int Splits, int w)
{
field[Lines][Splits]=w;
}
int Getmatrix (int Lines, int Splits)
{
return field[Lines][Splits];
}
};