title: Filling a vector with a custom defined class through pointers - trouble with constructor
body: <p>I'm interested in:</p>
  
  <ul>
  <li>having an std::vector of pointers to an user defined type/class</li>
  <li>filling this vector in the fastest way</li>
  </ul>
  
  <p>I would like to solve this with:</p>
  
  <ul>
  <li>while + iterators ( a non-C++11 solution )</li>
  <li>for_each iteration + lambda ( a c++11 solution )</li>
  </ul>
  
  <p>Now after reading the documentation I was trying this for the <code>iterator</code> part with the <code>while</code></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  class A{
    public:
      A(){}
      ~A(){}
    private:
      int n;
      double d;
      float f;
      std::string s;
  };
  
  int main(){
    std::vector&lt;A*&gt; v(100); // fixed *A to A*
    std::vector&lt;A*&gt;::iterator iter = v.begin(); // fixed *A to A*
    while( iter != v.end() )
    {
      *iter = new A(); // iter = A(); by the way this does not works either // now fixed using new
      ++iter;
    }
    return(0);
  }
  </code></pre>
  
  <p>i know that this is trivial but to me it's not, in my understanding iter it's a pointer and needs to be indirected to the real value that it is pointing in the vector; clearly this concept doesn't work this way.</p>
  
  <p>With the lambda and the for_each i just don't get how to use a constructor for a custom defined class because the documentation only talks about generic methods and functions and seems like i can't use a constructor.</p>
  
  <p>How i can build an object with iterators and lambdas ?</p>
  
  <p>Also, there is a faster way to cycle the entire vector when i need to perform the same action all over the place without using the iteration approach with the <code>while</code> and the <code>for_each</code> or the <code>for</code>.</p>
  
  <p>I would like to avoid the copy constructor overhead so i would like to keep all possible solutions using pointers.</p>
  
  <p>Thanks.</p>