Return value destructed in operator*
<p>I'm creating a multiplication operator overload. It's declared like this:</p>

<pre><code>T operator*(const T &amp; right);
</code></pre>

<p>It creates a local <em>T</em> object, calculates its values and returns it. The problem is that when it's getting returned it seems that it goes out of scope and its destructor is being called. AFAIK it shouldn't happen, because a return statement should create a copy. I'm not making any references to it; the object contains dynamically allocated memory, but it should be handled by an assignment operator which I made. So I've a line like this:</p>

<pre><code>t1 = t2 * t3;
</code></pre>

<p>where <em>t1</em>, <em>t2</em> and <em>t3</em> are <em>T</em> objects.</p>

<p>I've used my debugger and the local temporary <em>T</em> object inside <code>operator*</code> is fine, but the returned one lacks the dynamically allocated content.</p>

<p>What came into my mind is that the return statement does not copy my object correctly, because it didn't copy the dynamically allocated content because of lack of copy constructor. So I made a copy constructor like this:</p>

<pre><code>T(const T &amp; arg)
{
    *this = arg;
}
</code></pre>

<p>so it would use my assignment operator. And that's when things started getting weird. I was getting stack overflow (almost) every time when calling the copy constructor. And when debugging it seems that it didn't even call the assignment operator. What could be wrong?</p>