STL - Vector

Can somebody please explain what the second parameter means, or point me towards a reference where I can read about it. Thank you.

template < class T, class Allocator = allocator<T> > class vector;
An allocator is what it sounds like. In STL containers it deals with the behind-the-scenes allocation/reallocation/etc from adding to and deleting elements from the container. allocator<T> is just an instantiation of an allocator for type T.
Thanks,

my main query is regarding the syntax

class Allocator = allocator<T> <-- what is happening here?

I understand we are trying to parameterize the template here, similar to template<class T, int N> but fail to understand how the above syntax is similar to this. are we giving a default argument?
Last edited on
Yes that is giving a default argument. Here, it is using the default allocator. However you can specify you own allocator class which allocates memory and places objects in its own way and use that instead (useful if you want to do something like memory pooling).
I read a bit about it..I get it now..Thanks
Topic archived. No new replies allowed.