Original article link
By default, the class implements four functions: default constructor, copy constructor, destructor, and = Operator overload.
# Include <iostream> Using Namespace STD; Class Mystring { Public : Mystring ( Const Char * STR = Null); mystring ( Const Mystring & Other ); ~Mystring (); mystring & Operator = ( Const Mystring & Other); showstring (); Private : Char * M_data ;}; mystring :: ~ Mystring () {Delete [] m_data;} mystring: mystring ( Const Char * Str ){ If (STR =Null) {m_data = New Char [ 1 ]; * M_data = ' \ 0 ' ;} Else { Int Length = strlen (STR) + 1 ; M_data = New Char [Length]; While (* Str! = ' \ 0 ' ) * M_data ++ = * STR ++ ; * M_data = ' \ 0 ' ;} Mystring: mystring ( Const Mystring & Other ){ Int Length = strlen (other. m_data) + 1 ; M_data = New Char (Length); strcpy (m_data, other. m_data ); * M_data = ' \ 0 ' ;} Mystring & Mystring :: Operator = ( Const Mystring & Other ){ If (This == & Other ){ Return * This ;} Delete [] m_data; Int Length = strlen (other. m_data) + 1 ; M_data = New Char [Length]; strcpy (m_data, other. m_data ); Return * This ;} Mystring: showstring () {cout < This -> M_data < Endl ;} Int Main ( Int Argc, Char ** Argv) {mystring STR; Char * P = " Hello Peter " ; Mystring DEST (p); DeST. showstring (); Str = DeST; Str. showstring (); Return 0 ;}