The way you work with m_data is a nonsense.
Looking the
MyClass::MyClass
constructor, you first allocate 50 chars from the heap, assigning the address to
m_data
, then you assign to m_data the address of the literal
"You are someone"
. Since this point, the 50 chars you allocate are leaked (and unreachable) with
m_data
pointing to a constant literal, that you try do delete later on, in the destructor and in SetStr.
In MyClass::SetStr there is a (NULL==para) return;. It will make more sense if you place an
if
in front (is it a typo?!?).
In practice, string literal and character arrays don't work the way you think.
In particular
m_data = "You are someone!!";
doesn't copy the string into the array pointed by m_data.
To properly copy you should use library fuctions like
strcpy
or similar, the does a work like this:
void copy_string(char* dest, unsigned dest_sz, char* src)
{
unsigned i;
for(i=0; i<dest_sz-1 && src[i]; ++i)
dest[i] = src[i];
dest[i]='\0';
}