I'm writing my version of string class and when I tried to overload + operator, destructor triggers a breakpoint while the program is performing
function:
String operator+(const String & s, const String & st)
{
int k = s.len + st.len + 1;
char* x = new char[k];
x = s.str;
for (int i = 0, j = k - st.len - 1; j < k; j++, i++)
{
x[j] = st.str[i];
}
return String(x);
}
destructor:
String::~String()
{
delete[] str;
}
main:
int main()
{
String x("cos");
String y("cos");
String z = x + y;
std::cout << z;
}
thanks for help