title: Why is my copy constructor not working? (C++)
body: <p>I'm studying C++ and created this simple code to practice copy constructors.</p>
  
  <pre><code>class Cube{
      private:
          double length;
      public:
          Cube(){
              length = 1;
              cout &lt;&lt; "default constructor called" &lt;&lt; endl;
          };
          Cube(const Cube&amp; obj){
              length = obj.length;
              cout &lt;&lt; "copy constructor called" &lt;&lt; endl;
          };
  };
  
  Cube foo(){
      Cube c;
      return c;
  }
  
  int main(){
      Cube c2 = foo();
      return 0;
  }
  </code></pre>
  
  <p>I expected this to print<br>
  "default constructor called"<br>
  "copy constructor called"<br>
  "copy constructor called"<br>
  as default constructor is called in "Cube C", and copy constructor is called in "return c" and "Cube c2 = foo()".</p>
  
  <p>However my console only shows "default constructor called"</p>
  
  <p>Am I misunderstanding on how copy constructor works?</p>