+ 8
Explain Output please
Run this code multiple time you will get you will get different characters which are not supposed to be print . https://code.sololearn.com/crwwhuyG4wM1/?ref=app
2 ответов
+ 5
still it is giving unnecessary character in output.
+ 1
The + operator. has been wrongly overloaded, as you intend to use it as a binary operation (2 strings to one) but the copying part has some errors. I will just post the correct overloaded version.
Edit : Use this instead:
//overloading + operator
str operator+ (str s)
{
str temp; // No need of an extra char*.
temp.len=strlen(p)+strlen(s.p)+1;
temp.p=new char[temp.len];
strcpy(temp.p,p);
// Copy p to temp.
strcat(temp.p,s.p);
// Concat s.p to temp.
return temp;
}