问题
问答题
完成下面类中成员函数的定义。
#include<iostream>
#include<string>
using namespace std;
class str
private:
char*st;
public:
str(char*a)
set(a);
str&operator=(______)
delete st;
set(a.st);
return*this;
void show()cout<<st<<endl;
~str()delete st;
void set(char*s)//初始化st
______
strcpy(st,s);
;
void main()
str s1("he"),s2("she");
s1.show(),s2.show();
s2=s1;
s1.show(),s2.show();
答案
参考答案:str &a
st=new char[strlen(s)+1];