class S {
public:
const char* strp;
int length;
void Ini(const char* s);
void Print(void);
void Copy(S& s);
};
void main(void)
{
S s1, s2;
s1.Ini("China");
s2.Ini("");
s1.Print();
s2.Copy(s1);
s2.Print();
s1.Copy(s1);
}
void S::Ini(char* s)
{
length = strlen(s);
strp = new char[length + 1];
strcpy(strp, s);
}
void S::Print(void)
{
cout << strp << endl;
}
void S::Copy(S& s)
{
if (strp)
delete[]strp;
length = s.length;
strp = new char[length + 1];
strcpy(strp, s.strp);
}


public:
const char* strp;
int length;
void Ini(const char* s);
void Print(void);
void Copy(S& s);
};
void main(void)
{
S s1, s2;
s1.Ini("China");
s2.Ini("");
s1.Print();
s2.Copy(s1);
s2.Print();
s1.Copy(s1);
}
void S::Ini(char* s)
{
length = strlen(s);
strp = new char[length + 1];
strcpy(strp, s);
}
void S::Print(void)
{
cout << strp << endl;
}
void S::Copy(S& s)
{
if (strp)
delete[]strp;
length = s.length;
strp = new char[length + 1];
strcpy(strp, s.strp);
}


