#include
#include
#include
#include
using namespace std;
The class MyWord
{
Public:
//define myword members of the class data
Static int num.
Char * pdata;
Int length;
Const int a;
Friend ostream& Operator<(ostream& , MyWord&);//declare friend yuan overloaded operators "& lt; & lt;" The function
Friend istream& Operator> (istream& , MyWord&);//declare friend yuan overloaded operators & gt; "" & gt;" The function
//constructor initializes a
MyWord (char * pd="qwertyuiopasdfghjkl, int n=0) : a (n)
{
Length=strlen (pd);
Pdata=https://bbs.csdn.net/topics/new char [length + 1];
Strcpy (pdata, pd);//copies string pd to pdata
cout <"To start the calls the constructor... "& lt;
//class of deep copy constructor
MyWord (const MyWord& S) : a (s.a)
{
Length=s.l ength;
Pdata=https://bbs.csdn.net/topics/new char [length + 1];
Strcpy (pdata, supachai panitchpakdi data);
cout <"The deep copy constructor" & lt;
}
MyWord operator=(const MyWord& S)//overloaded=
{
Length=s.l ength;
Pdata=https://bbs.csdn.net/topics/new char [length + 1];
Strcpy (pdata, supachai panitchpakdi data);
cout <"Call the overloading of the equal sign" & lt;
}
~ MyWord ();//
};
Ostream& Operator<(ostream& OS, MyWord& MW)
{
OS & lt;
}
Istream& Operator> (istream& Is, MyWord& MW)
{
Is & gt;> MW. Pdata;
The return is;
}
Int MyWord: : num=0;
The class Sentence: MyWord
{
Public:
Vector
Void Length ();
Void the Add ();
Void the Show ();
Void Menu ();
};
//destructors
MyWord: : ~ MyWord ()
{
cout <"Start the destructor call... "& lt;
The delete pdata;//data release
}
Void Sentence: : Length ()
{
cout <& lt;" Sentence length is: "& lt;
Void Sentence: : Add ()
{
MyWord word;
While (cin & gt;> Word)
{
Amy polumbo ush_back (word);
}
}
Void Sentence: : Show ()//for
{
Vector
for (; m !=a.e nd (); + + m)
{
cout <* m & lt;
}
Void Sentence: : Menu ()
{
cout
}
MyWord f (MyWord A)
{
MyWord D (" abs ", 3);
Return D;
}
Int main ()
{
//test for
cout <"* * * * * * * * * * * * * * * * * * * * * * * *" & lt;
MyWord C=A;//test deep copy function
C=f (A);
cout <"* * * * * * * * * * * * * * * * * * * * * * * *" & lt;
Char flag='1';
What S;
While (flag!='0')
{
S.M emu ();
cin> Flag;
If (flag=='1')
S.A dd ();
Else if (flag=='2')
S.S how ();
Else if (flag=='3')
S.L ength ();
Else if (flag=='0');
The else
{
cout <"Input error" & lt;
}
}
}

CodePudding user response:
Have a memory leak, the operator=, followed by the operator should return references