title: C++ Copy Constructors
body: <p>I recently wrote a piece of code which did</p>
  
  <pre><code>SomeClass someObject;
  mysqlpp::StoreQueryResult result = someObject.getResult();
  </code></pre>
  
  <p>where SomeClass::getResult() looks like:</p>
  
  <pre><code>mysqlpp::StoreQueryResult SomeClass::getResult()
  {
  mysqlpp::StoreQueryResult res = ...&lt;something&gt;...;
  return res;
  }
  </code></pre>
  
  <p>Now, using the example in the first code snippet, when I compiled and ran, the program crashed with an ABORT signal.  I then changed the first snippet to:</p>
  
  <pre><code>SomeClass someObject;
  mysqlpp::StoreQueryResult result(someObject.getResult());
  </code></pre>
  
  <p>which worked fine.  Also, just to try it out, I changed it again to:</p>
  
  <pre><code>SomeClass someObject;
  mysqlpp::StoreQueryResult result;
  result = someObject.getResult();
  </code></pre>
  
  <p>which also worked fine.</p>
  
  <p>Now, I just can't figure out why the first example failed, and the next two succeeded.  As I understand, in the first example, the copy constructor is used to initialise result.  But isn't this also the case in the second example?  So why did the second example succeed?  The 3rd example makes a bit more sense - since the copy const isn't used, we just assign after construction.</p>
  
  <p>In short, what's the difference between:</p>
  
  <pre><code>FooClass a = someObject.someMethodReturningFooClassInstance();
  </code></pre>
  
  <p>and </p>
  
  <pre><code>FooClass a(someObject.someMethodReturningFooClassInstance());?
  </code></pre>
  
  <p>Muchos thanks!</p>