[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: porting error I don't understand
From: |
mark |
Subject: |
Re: porting error I don't understand |
Date: |
13 May 2005 06:01:32 -0700 |
User-agent: |
G2/0.2 |
> So, the correct operator=() signature should be:
>
> Matrix& operator=( const Matrix& A );
Well, here's a funny thing now... I tried this:
Matrix& Matrix::operator=( const Matrix& A ) /* assignment operator
overload */
{
if( ( void * )( &A ) == ( void * )( this ) ) /* if nothing to do
... */
return( *this );
if( Data != NULL ) /* if contains data, free it... */
free( Data );
R = A.R; /* copy the fields */
C = A.C;
TheCopyFlag = 0; /* but set copy flag to clear now... */
Type = A.Type;
Data = NULL;
if( Type != Undefined )
{
if( A.TheCopyFlag ) /* the fast pass-through method... */
{
Data = A.Data;
A.Data = NULL; <<<<======= mind that one !!!!
return( *this );
}
/* if normal mode than do allocate and copy the stuff... */
Data = ( complex * )( malloc( MatrixDataSize( A ) ) );
if( Data == NULL )
{
MatrixErrorFunc( MemoryError );
C = 0;
R = 0;
Type = Undefined;
return( *this );
}
memcpy( Data, A.Data, MatrixDataSize( A ) );
}
return( *this ); /* return ref to this matrix */
}
As far as I understand, the const keyword, without defining the Data
member of the Matrix class to be "mutable", should not allow me to do
that. But it compiles ?! Is this a "hidden" feature of g++ or am I
misunderstanding things again?
best regards,
mark somers.