title: When is it safe to rely on an implicit copy constructor?
body: <p>In this very simple program the constructor is called once, but the destructor is called twice:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class CTest
  {
  public:
    int m_val;
    CTest(int val);
    ~CTest();
  };
  
  
  CTest::CTest(int val) : m_val(val)
  {
    cout &lt;&lt; "construct " &lt;&lt; m_val &lt;&lt; '\n';
  }
  
  CTest::~CTest()
  {
    cout &lt;&lt; "delete " &lt;&lt; m_val &lt;&lt; '\n'; m_val = 77777;
  };
  
  int main() {
    CTest a(2);
    CTest b = a;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>construct 2
  delete 2
  delete 2
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>construct 2
  delete 2
  </code></pre>
  
  <p>This is actually because of the implicit copy constructor (correct me if I'm wrong).</p>
  
  <p>Do I need to define a copy constructor here or is it safe to rely on the implicit copy constructor?</p>
  
  <p>Same question if I have non POD class members (such as <code>std::string</code>)?</p>