下面的程序是在str类中重载运算符=,请将程序补充完整,使程序的输出结果为:
he
she
he
he
#include <iostream>
using namespace std;
class str
{
private:
char *st;
public:
str(char *a)
{
set(a);
}
str & perator=(## )
{
delete []st;
set(a.st);
return *this;
}
void show()
{
cout<<st<<endl;
}
~str()
{
delete []st;
}
void set(char *s)
{
st=new char[strlen(s)+1];
strcpy(st,s);
}
};
int main()
{
str s1("he"),s2("she");
s1.show();
s2.show();
##;
s1.show();
s2.show();
}