title: C++ destructors question
body: <p>With regards to the sample code below, why is the destructor for the base class called twice?  </p>
  
  <pre><code>class Base {
  public:
      Base() {
          std::cout &lt;&lt; "Base::Base()" &lt;&lt; std::endl;
      }
  
      ~Base() {
          std::cout &lt;&lt; "Base::~Base()" &lt;&lt; std::endl;
      }
  };
  
  class Derived : public Base {
  public:
      Derived() {
          std::cout &lt;&lt; "Derived::Derived()" &lt;&lt; std::endl;
      }
  
      ~Derived() {
          std::cout &lt;&lt; "Derived::~Derived()" &lt;&lt; std::endl;
      }
  };
  
  int main() {
      Base a = Derived();
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>Here is a sample of the output when the program is run:</p>
  
  <pre><code>Base::Base()
  Derived::Derived()
  Derived::~Derived()
  Base::~Base()
  Base::~Base()
  </code></pre>