title: How to call constructor of objects contained in a std::vector?
body: <p>When I create a std::vector of objects, the constructor of these objects is not always called. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  struct C {
      int id;
      static int n;
      C() { id = n++; }   // not called
  //  C() { id = 3; }     // ok, called
  };
  
  int C::n = 0;
  
  
  int main()
  {
      vector&lt;C&gt; vc;
  
      vc.resize(10);
  
      cout &lt;&lt; "C::n = " &lt;&lt; C::n &lt;&lt; endl;
  
      for(int i = 0; i &lt; vc.size(); ++i)
          cout &lt;&lt; i &lt;&lt; ": " &lt;&lt; vc[i].id &lt;&lt; endl;  
  }
  </code></pre>
  
  <p>This is the output I get:</p>
  
  <pre><code>C::n = 1
  0: 0
  1: 0
  2: 0
  ...
  </code></pre>
  
  <p>This is what I would like:</p>
  
  <pre><code>C::n = 10
  0: 0
  1: 1
  2: 2
  ...
  </code></pre>
  
  <p>In this example, am I forced to resize the vector and then initialise its elements "manually"?<br>
  Could the reason be that the elements of a vector are not initialised in an ordered way, from the first to the last, and so I cannot obtain a deterministic behaviour?  </p>
  
  <p>What I would like to do, is to easily count the number of objects created in a program, in different containers, in different points of the code, and to give a single id to each of them.</p>
  
  <p>Thank's! </p>