Basic question about std::vector instantiation

Posted by recipriversexclusion on Stack Overflow See other posts from Stack Overflow or by recipriversexclusion
Published on 2010-03-13T15:45:55Z Indexed on 2010/03/13 16:05 UTC
Read the original article Hit count: 337

Filed under:
|
|

This looks simple but I am confused: The way I create a vector of hundred, say, ints is

std::vector<int>  *pVect = new std::vector<int>(100);

However, looking at std::vector's documentation I see that its constructor is of the form

explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );

So, how does the previous one work? Does new call the constructor with an initialization value obtained from the default constructor? If that is the case, would

std::vector<int, my_allocator> *pVect = new std::vector<int>(100, my_allocator);

where I pass my own allocator, also work?

© Stack Overflow or respective owner

Related posts about stl

Related posts about stdvector