[求助]怎么改
#include <iostream>using namespace std;
class String
{
public:
String(){p=NULL;}
String(char *str);
friend String operator+(String &string1,String &string2);
void display();
private:
char *p;
};
String::String(char *str)
{p=str;}
void String::display()
{cout<<p<<endl;}
String operator+(String &string1,String &string2)
{
String string3;
int i,j,lenth_1,lenth_2;
for(i=0,lenth_1=0;string1.p[i]!='\0';i++) lenth_1++;
for(j=0,lenth_2=0;string2.p[j]!='\0';j++) lenth_2++;
i=0;
while(i<lenth_1)
{
string3.p[i]=string1.p[i];//有问题栈益出
i++;
}
j=0;
while(j<lenth_2)
{
string3.p[lenth_1+j]=string2.p[j];
j++;
}
string3.p[lenth_1+lenth_2]='\0';
return string3;
}
void main()
{
String string1("hello"),string2("book"),string;
string=string1+string2;
string.display();
}
请高手指教