Jan 30, 2013 at 11:33pm UTC
How would I add my own function to the vector class?
Jan 31, 2013 at 12:08am UTC
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.
Jan 31, 2013 at 2:04am UTC
Hi hopesfall,
Just wondering what you want to do exactly? Is it to do with your word storing program? Hope that is going well.
Jan 31, 2013 at 2:11am UTC
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 Jan 31, 2013 at 2:13am UTC