In this example where is the C++ assignment operator used rather than the copy constructor?
<p>As part of an ongoing process of trying to upgrade my C++ skills, I am trying to break some old habits. My old school C programmer inclination is to write this;</p>

<pre><code>void func( Widget &amp;ref )
{
    Widget w;  // default constructor
    int i;
    for( i=0; i&lt;10; i++ )
    {
        w = ref;  // assignment operator 
        // do stuff that modifies w
    }
}
</code></pre>

<p>This works well. But I think the following is closer to best practice;</p>

<pre><code>void func( Widget &amp;ref )
{
    for( int i=0; i&lt;10; i++ )
    {
        Widget w = ref; // ??
        // do stuff that modifies w
    }
}
</code></pre>

<p>With my Widget class at least, this works fine. But I don't fully understand why. I have two theories;</p>

<p>1) The copy constructor runs 10 times.<br>
2) The copy constructor runs once then the assignment operator runs 9 times.</p>

<p>Both of these trouble me a little. 2) in particular seems artificial and wrong. Is there a third possibility that I am missing ?</p>
