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.
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:
template< class Type, class Allocator = allocator< Type > >
class extendedVector : public vector<Type,Allocator>
// put extra functions here
This means that you can use the extendedVector class if you want the extra functions, but the vector class is still untouched.
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