Destructor triggers a breakpoint : <p>I'm writing my version of string class and when I tried to overload + operator, destructor triggers a breakpoint while the program is performing</p>

<p>function:</p>

<pre><code>String operator+(const String &amp; s, const String &amp; 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 &lt; k; j++, i++)
    {
        x[j] = st.str[i];
    }
    return String(x);
}
</code></pre>

<p>destructor:</p>

<pre><code>String::~String()
{
    delete[] str;
}
</code></pre>

<p>main:</p>

<pre><code>int main()
{
    String x("cos");
    String y("cos");
    String z = x + y;
    std::cout &lt;&lt; z;
}
</code></pre>

<p>thanks for help</p>
