就一点c++的内容,不知道为什么就出错
#include<iostream.h>
#include<string.h>
class string
{
private:
char * str;
public:
string(char * s="")
{
str=new char[strlen(s)+1];
strcpy(str,s);
}
~string(){delete []str;}
void display()
{
cout<<str<<endl;
}
friend string operator +(string & s1,string & s2);
};
string operator +(string & s1,string & s2)
{
string temp;
temp.str =new char[strlen(s1.str)+strlen(s2.str)+1];
strcpy(temp.str ,s1.str);
strcat(temp.str ,s2.str);
return(temp);
}
void main()
{
string s1("dddd");
string s2("dsfas");
string myname(operator +(s1,s2));
myname.display();
}