#include
using namespace std;
class UString
{
protected:
char *str;
int len;
public:
UString()
{
str=0;
len=0;
}
UString(char *c)
{
len=strlen(c);
str=new char(len+1);
strcpy(str,c);
}
UString(UString &a)
{
if(!str) delete str;
str=new char[strlen(a.str)+1];
strcpy(str,a.str);
}
~UString()
{
delete str;
}
UString operator+(const UString &a)
{
UString temp;
temp.str=new char[strlen(str)+strlen(a.str)+1];
strcpy(temp.str,str);
strcat(temp.str,a.str);
return temp;
}
void show()
{
cout<<str<<endl;
}
};
int main()
{
UString str1("abc"),str2("def"),c;
c=str1+str2;
c.show();
return 0;
}
求大神解答下!!