Code:
void CString::Copy( const CString& string )
{
if( this != &string )
{
if( string.IsValid() )
{
const TCHAR* data = NULL;
int len = string.Length();
// this is probably unnecessary
if( m_Data != NULL )
{
delete [] m_Data;
m_Data = NULL;
m_Length = 0;
m_Size = 0;
m_isValid = false;
}
m_Data = new TCHAR[len + 1 ];
data = string.C_Str();
for( int index = 0; index < len; ++index )
m_Data[index] = data[index];
m_Length = len;
m_Size = CalcSizeInBytes();
m_Data[m_Length] = '0';
m_isValid = true;
}
}
}
Problem:
Code:
CString string( _T( "Hello World" ) );
CString me;
me = _T( "Ervin Ashley" );
me = string;
comes out as:
string = Hello World
me = Hello World0
but I cant find anything wrong with my code.
My other copy function works just fine.