title: C++ vectors of classes with constructors
body: <pre><code>//Using g++ and ubuntu.
  #include &lt;vector&gt;
  using namespace std;
  </code></pre>
  
  <p>Define a class:</p>
  
  <pre><code>class foo(){
  (...)
  foo(int arg1, double arg2);
  }
  </code></pre>
  
  <p>Constructor:</p>
  
  <pre><code>foo::foo(int arg1, double arg2){ 
  (...) //arrays whose length depend upon arg1 and arg2
  } 
  </code></pre>
  
  <p>I would like to do something like this:</p>
  
  <pre><code>vector&lt;foo&gt; bar(10); //error: no matching function for call to 'foo::foo()'
  bar[0] = new foo(123, 4.56);
  (...)
  </code></pre>
  
  <p>An alternative method (which I like less) is to use push_back:</p>
  
  <pre><code>vector&lt;foo&gt; bar; //works
  bar.push_back(new foo(123, 4.56)); //throws similar error.
  //Omitting the "new" compiles but throws a "double free or corruption (fasttop)" on runtime.
  </code></pre>
  
  <p>I want different elements of the vector to be constructed differently, so I don't want to use the "Repetitive sequence constructor".
  What should be done?</p>