title: Why there is a copy before assign?
body: <p>I am doing the following test:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  class A
  {
  private:
     int i;
  public:
     A():i(1){cout&lt;&lt;"A constr"&lt;&lt;endl;}
     A(const A &amp; a):i(a.i){cout&lt;&lt;"A copy"&lt;&lt;endl;}
     virtual ~A(){cout&lt;&lt;"destruct A"&lt;&lt;endl;}
     void operator=(const A a){cout&lt;&lt;"A assign"&lt;&lt;endl;}
  };
  
  
  int main()
  {
     A o1; 
     A o2; 
     o2=o1;
  }
  </code></pre>
  
  <p>And the output is:</p>
  
  <pre><code>A constr
  A constr
  A copy
  A assign
  destruct A
  destruct A
  destruct A
  </code></pre>
  
  <p>It seems that "o2=o1" did a copy first followed by an assignment, and I wonder what's the story behind it. Thanks!</p>