I have a simple class called String which has as a private field a char*.
class String { char *s; + some public methods }; I want to overload the + operator so a + b would mean that the strings from a and b are concatenated.
The function is here:
String String::operator+(String a) { String rez; rez.s = new char[strlen(this->s) + strlen(a.s) + 1]; assert(rez.s); strcpy(rez.s, this->s); strcat(rez.s, a.s); cout<<rez.s<<endl; // HERE rez.s CONTAINS THE RIGHT STRING! return rez; } After I call this: c = a + b;
i get an error called Debug assertion failed.
Any ideas?
typedef String std::string;