class Name {
char *mp; // since mp is declared first in the class, it in initialized first
int mlen; // mlen is initialized after mp
public:
// the order you put them in here doesn't matter:
Name(constchar *pname) : mlen(strlen(pname)), mp(newchar[mlen + 1])
// therefore, you are using mlen before it was initilized.
To correct this, declare mlen before mp, or allocate mp in the body of the ctor.
Also, don't forget to delete[] mp in your dtor and write a proper copy ctor and assignment operator.
Because mlen gets initialized after mp
The order of initialization of class members depends on the order of their declarations
Your compiler should give a warning on the code above