Adding additional functions to the STL vector class

How would I add my own function to the vector class?
You can't without modifying the class definition itself (don't do this) but you could just make a function that takes a reference to a vector as its first parameter.
Hi hopesfall,

Just wondering what you want to do exactly? Is it to do with your word storing program? Hope that is going well.
You could make an inherited child of the vector class, like so:

1
2
3
4
5
template< class Type, class Allocator = allocator< Type > >
class extendedVector : public vector<Type,Allocator>
{
// put extra functions here
};


EDIT:

This means that you can use the extendedVector class if you want the extra functions, but the vector class is still untouched.

EDIT 2:

Note that this doesn't give you access to the vector class's private members, which is usually where its actual data is stored
Last edited on
Topic archived. No new replies allowed.