Have you ever thought how Vector works internally?
Vectors are sequence containers representing arrays that can change their size during "runtime".
Here,Runtime word is more important because changing size at runtime is important functionality of vector.
I have created a prototype for vector class which includes push_back(),pop_back(),size() functions and with that templates are also used to make class generic.
vector allocates double space in memory if current size is reached it's maximum and if user has given vector size manually but have added more elements then vector dynamically increases it's space.
So what are templates? it's formula to make class generic(to work for variety of datatypes).
You can run below code and can use for variety of datatypes.
Stay Curious! Stay Happy!
Check main.cpp file for full source code....
#Technology#Creativity#programminglife #coderlife #developerlife #codinglife #computerscience #codelife #code #science #softwaredevelopment