What strange magic is *this?
<p>Quick question.  I want to understand the behaviour of *this in C++.
Forgive me if this is too obvious, or is a repeat, due to search engines interpreting * as a wildcard character my searches have been somewhat less than enlightening.</p>

<p>I'm using someone else's code, which has a number of functions that look like so:</p>

<p>(Type of N is struct)</p>

<pre><code>N N::someMethod() const {

    N n = *this;
    // do a function that modifies internal values of the struct
    n.modify();
    return n;

}
</code></pre>

<p>What happens is that it returns a modified copy of the original struct, and the original struct is unmodified.</p>

<p>I assume that somehow *this is making a copy, but I don't understand why/how.  Is this some magic to do with structs?  Is it the const in the function declaration?  Is there some other magic going on behind the scenes?</p>

<p>My understanding is that 'this' is a pointer.  I had thought that when you * a pointer, it simply dereferenced that pointer??  (So I expected n to point to the same chunk of memory as the original, but obviously it doesn't, so my intuition is borken)</p>

<p>Please feel free to point out the error of my ways, in detail if you like.  It's okay, I'm smart enough to grok a detailed technical discussion of what is going on under the hood, I promise! </p>
