title: Destructor of vector of object
body: <p><strong>Hello,</strong></p>
  
  <p>I have in my class Ordinateur a vector of *Composant :</p>
  
  <pre><code>class Ordinateur {
  
  string type;
  vector&lt;Composant*&gt; Composants;
  
  ...
  
  }
  </code></pre>
  
  <p>How do i write my destructor ? I read <strong>a lot of contradictory answers</strong> here on StackOverflow so i'm a bit lost.</p>
  
  <p><strong>1st version :</strong></p>
  
  <pre><code>virtual ~Ordinateur()
  {
      for (int i = 0; i &lt; Composants.size(); i++)
      {
          delete Composants[i];
      }
      Composants.clear();
  }
  </code></pre>
  
  <p><strong>2nd Version</strong></p>
  
  <pre><code>virtual ~Ordinateur()
  {
      Composants.clear();
  }
  </code></pre>
  
  <p><strong>What about :</strong></p>
  
  <pre><code> virtual ~Ordinateur()
  {
      for (int i = 0; i &lt; Composants.size(); i++)
      {
          delete Composants[i];
      }
  
  }
  </code></pre>
  
  <p>I would like to avoid memory leaks ...</p>