title: Why is a destructor called if it's deleted and not called if it's not deleted?
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A 
  {
      A(){ };
      ~A(){ std::cout &lt;&lt; "~A::A()" &lt;&lt; std::endl; };
  };
  
  struct B: A { };
  
  B *b = new B; //Doesn't produce any side-effect.
  
  int main(){ }
  </code></pre>
  
  <p><strong><a href="http://coliru.stacked-crooked.com/a/29842316b0179741" rel="noreferrer">DEMO</a></strong></p>
  
  <p>The program doesn't produce any output which means the destructor isn't being called. But if we replace the destructor's body with the <code>delete</code> specifier, the program won't even compile. </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A 
  {
      A(){ };
      ~A() = delete; //{ std::cout &lt;&lt; "~A::A()" &lt;&lt; std::endl; };
  };
  
  struct B: A { };
  
  B *b = new B; //Error: use of deleted function
  
  int main(){ }
  </code></pre>
  
  <p><strong><a href="http://coliru.stacked-crooked.com/a/9cf074c19572a3fb" rel="noreferrer">DEMO</a></strong></p>
  
  <p>due to call to the deleted function. That's the destructor that is being called in that case. Why is there such a difference?</p>
  
  <p>It won't work even if we define <code>B</code>'s constructor explicitly:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct A 
  {
      A(){ };
      ~A() = delete; //{ std::cout &lt;&lt; "~A::A()" &lt;&lt; std::endl; };
  };
  
  struct B: A 
  { 
      B(){ };
  };
  
  B *b = new B;
  
  int main(){ }
  </code></pre>
  
  <p><strong><a href="http://coliru.stacked-crooked.com/a/99a16549b4c21738" rel="noreferrer">DEMO</a></strong></p>