title: Why is the copy constructor being called before deleting the object?
body: <p>I have the following class, which includes a copy constructor:</p>
  
  <p><strong>Header File: Fred.h</strong></p>
  
  <pre><code>namespace foo {
  
  
  class Fred {
  private:
      int _x;
      int _y;
  
  
  public:
      Fred();                         // Default constructor
      Fred(Fred const &amp;other);        // Copy constructor
      Fred(int x, int y);             // Regular parameters
      ~Fred();                        // Destrcutor
  
  };
  
  
  }
  </code></pre>
  
  <p><strong>Implementation File: Fred.cpp</strong></p>
  
  <pre><code>#include "Fred.h"
  #include &lt;iostream&gt;
  
  foo::Fred::Fred(){
      _x = 0;
      _y = 0;
  
      std::cout &lt;&lt; "Calling the default constructor\n";
  }
  
  foo::Fred::Fred(Fred const &amp;other){
  
      _x = other._x;
      _y = other._y;
  
      std::cout &lt;&lt; "Calling the copy constructor";
  }
  
  foo::Fred::Fred(int x, int y){
      _x = x;
      _y = y;
  
      std::cout &lt;&lt; "Calling the convenience constructor\n";
  }
  
  foo::Fred::~Fred(){
  
      std::cout &lt;&lt; "Goodbye, cruel world!\n";
  }
  </code></pre>
  
  <p>I was expecting to see the destructor called when it got out of scope, instead, the copy constructor was called and then the destructor. Why was a copy created? Am I leaking memory?</p>
  
  <pre><code>using namespace foo;
  
  int main(int argc, const char * argv[])
  {
  
  
  
      {
          Fred f2 = *new Fred();
  
      } // I was expecting to see a destructor call only
  
  
      return 0;
  }
  </code></pre>