关于操作符重载问题
‘=’‘+’的重载,为什么说Could not find a match for 'MyString::operator =(MyString)'
MyString operator=(MyString &str)//重载“=”运算符
{
int size=strlen(str.pstr)+1;
char *p=this->pstr;
this->pstr=new char[size];
strcpy(this->pstr,str.pstr);
delete [] p;
return *this;
}
MyString operator+(MyString &str)//重载“+”运算符
{
int size=strlen(this->pstr)+strlen(str.pstr)+1;
MyString tempstr;
tempstr.pstr =new char[size];
strcpy(tempstr.pstr,this->pstr);
strcat(tempstr.pstr,str.pstr);
return tempstr;
}
main()
{
a=b;//通过
e=b+c;//重载“+”运算符//这里出的问题
}