title: How can I create objects while adding them into a vector?
body: <p>I have a C++ vector. I want the vector to hold a variable number of objects. </p>
  
  <p>Visual Studio 2012 is giving me an error:  </p>
  
  <pre><code>Error: type name is not allowed
  </code></pre>
  
  <p>From this C++ code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class testObject{
  private:
     int someInt;
  public:
     testObject(int a){ someInt=a; }
     void show() { cout&lt;&lt;someInt&lt;&lt;endl; }
  };
  
  int main()
  {
      vector&lt;testObject&gt; testVector;
      cout &lt;&lt; "Initial size: " &lt;&lt; testVector.size() &lt;&lt;endl;
  
      for ( int i = 0; i &lt; 3; i++ )
          testVector.push_back(testObject(3));
      cout &lt;&lt; "New size: " &lt;&lt; testVector.size() &lt;&lt; endl;
  
      for ( int j = 0; j &lt; 3; j++ )
          testVector[ j ].show();
  
      system("pause");
  }    
  </code></pre>
  
  <p>But here's another sample of code that looks the same but it's not working.</p>
  
  <pre><code>void Dealer::setNumberOfPlayers( const int tNumber )
  {
      for ( int i = 0; i &lt; tNumber; i++ )
          vectorOfGamers.push_back(Player); // Player is a class that I created
  }
  </code></pre>
  
  <p>Can I create vector to hold objects of Dealer, Bot and Player at the same time? How do I do that? As I know, all objects in vector should be of one type.</p>