E
E G
Hi,
I have a class similar to this:
class Matrix
{
private:
float **_A;
unsigned _rows,_cols;
public:
Matrix():_A(0),_rows(0),_cols(0){}
Matrix(unsigned const rows,unsigned const cols):_A(0),_rows(0),_cols(0)
{
if(rows>0 && cols>0){
_A=new float*[rows];
if(_A==0)
throw "Not Enough Memory";
_A[0]=new float[rows*cols];
if(_A[0]==0){
delete[] _A;
_A=0;
throw "Not Enough Memory";
}
if(rows>1)
for(unsigned i=1;i<rows;i++)
_A=_A[0]+ i*cols;
_rows=rows;
_cols=cols;
memset(_A[0],0,rows*cols*sizeof(float));
}
}
~Matrix()
{
if(_A != 0){
if(_A[0] != 0)
delete [] _A[0];
delete [] _A;
}
_A=0;
_rows=0;
_cols=0;
}
}
when I run a program similar to the following:
int main( int argc, char **argv )
{
Matrix *pfM;
{
Matrix fM(4,3);
pfM=&fM;
}
delete pfM;
return 0;
}
the following happens:
int main( int argc, char **argv )
{
Matrix *pfM;
{
Matrix fM(4,3); <------- fM._A has some assigned address as expected.
I have a class similar to this:
class Matrix
{
private:
float **_A;
unsigned _rows,_cols;
public:
Matrix():_A(0),_rows(0),_cols(0){}
Matrix(unsigned const rows,unsigned const cols):_A(0),_rows(0),_cols(0)
{
if(rows>0 && cols>0){
_A=new float*[rows];
if(_A==0)
throw "Not Enough Memory";
_A[0]=new float[rows*cols];
if(_A[0]==0){
delete[] _A;
_A=0;
throw "Not Enough Memory";
}
if(rows>1)
for(unsigned i=1;i<rows;i++)
_A=_A[0]+ i*cols;
_rows=rows;
_cols=cols;
memset(_A[0],0,rows*cols*sizeof(float));
}
}
~Matrix()
{
if(_A != 0){
if(_A[0] != 0)
delete [] _A[0];
delete [] _A;
}
_A=0;
_rows=0;
_cols=0;
}
}
when I run a program similar to the following:
int main( int argc, char **argv )
{
Matrix *pfM;
{
Matrix fM(4,3);
pfM=&fM;
}
delete pfM;
return 0;
}
the following happens:
int main( int argc, char **argv )
{
Matrix *pfM;
{
Matrix fM(4,3); <------- fM._A has some assigned address as expected.