title: Why does whether a struct's destructor runs depend on the type of a member variable?
body: <p>I'm fairly new to C++ and when wandering around the constructor and destructor behavior I found this problem:</p>
  <pre><code>#include &lt;iostream&gt;
  
  struct Student {
      std::string a;
      ~Student() {
          std::cout &lt;&lt; &quot;Destructor called\n&quot;;
      }
  } S;
  
  int main() {
      std::cout &lt;&lt; &quot;Before assigning to S\n&quot;;
      S = {&quot;&quot;};
      std::cout &lt;&lt; &quot;After assigning to S\n&quot;;
  }
  </code></pre>
  <p>When I compile the code above with <code>g++</code> and run it, it prints:</p>
  <pre><code>Before assigning to S
  Destructor called
  After assigning to S
  Destructor called
  </code></pre>
  <p>But when I change <code>std::string a;</code> to <code>const char *a;</code>, then it prints:</p>
  <pre><code>Before assigning to S
  After assigning to S
  Destructor called
  </code></pre>
  <p>Can anyone explain why this change makes the destructor run one fewer time?</p>