title: Initializing std::vector of std::string
body: <p>While working in a project with some legacy code i found this function:</p>
  
  <pre><code>std::vector&lt;std::string&gt; Object::getTypes(){
      static std::string types [] = {"type1","type2", "type3"};
      return std::vector&lt;std::string&gt; (types , types +2);
  }
  </code></pre>
  
  <p>I would probably have written this as:</p>
  
  <pre><code>std::vector&lt;std::string&gt; Object::getTypes(){
      std::vector&lt;std::string&gt; types;
      types.push_back("type1");
      types.push_back("type2");
      types.push_back("type3");
      return types;
  }
  </code></pre>
  
  <p>Is this merely a style choice or is there something I'm missing? Any help would be greatly appreciated. Sorry if this is too basic. </p>
  
  <p><strong>Update:</strong>
  Actually found different classes that override the same method do it one way or the other, so It's even more ambiguous. I would make them all the same but would prefer the better approach, if there is one.</p>
  
  <hr>
  
  <p><em>Edit</em></p>
  
  <p>Please note that the above legacy code is incorrect because it initializes the vector with only the first two elements of the array. However, this error has been discussed in the comments and thus should be preserved.</p>
  
  <p>The correct initialization should have read as follows:</p>
  
  <pre><code>...
      return std::vector&lt;std::string&gt; (types, types + 3);
  ...
  </code></pre>