The prototype of a known string is
Class string
{
Public:
String (const char * STR = NULL); // common Constructor
String (const string & other); // copy the constructor
~ String (void); // destructor
String & operate = (const string & other); // value assignment function
PRIVATE:
Char * m_date; // used to save the string
};
0
- Hufeng3405871
- Intermediate FAN 2
/* Common constructor */
String (const char * STR = NULL)
{
If (STR = NULL)
{
M_date = new char [1];
* M_date = '/0 ';
}
Else
{
Int long = strlen (STR );
This-> m_date = new char [long + 1];
Strcpy (m_dat, STR );
}
}
Reply
- Hufeng3405871
- Intermediate FAN 2
/* Copy the constructor */
String (const string & other)
{
Int long = strlen (other. m_date );
M_date = new char [long + 1];
Strcpy (m_date, other. m_date );
}
Reply
- Hufeng3405871
- Intermediate FAN 2
/* Constructor */
~ String (void)
{
Delete [] m_date;
}
Reply
- Hufeng3405871
- Intermediate FAN 2
/* Value assignment function */
String operate (const string & other)
{
If (this = & other)
{
Return * this;
Delete [] m_date;
}
Else
{
Int long = strlen (other. m_date );
M_date = new char [long + 1];
Strcpy (m_date, other. m_date );
Return * this;
}
}