Question: Create your own vector class that has the following properties: 1) A push_back method which adds an item to the end of the vector, expanding
Create your own vector class that has the following properties: 1) A push_back method which adds an item to the end of the vector, expanding the underlying data storage as needed. 2) A pop_back method which returns the last item in the vector and removes it, shortening the length of the vector by 1. 3) A size method which returns how many items are in the vector 4) A capacity method which returns the number of items that the vector can hold before it needs to expand it's underlying storage 5) An ensure_capacity method which sets the size of the underlying data store to a specific length. After ensure_capacity is run, the capacity function should return at LEAST the value passed into ensure_capacity 6) An overloaded Index ([]) operator which allows a user to get an item at a specified index (ex: myvector[3] would get the item at index 3 in the vector)
--++Use C++ templates to ensure that your vector class can accept any data type and Name your class "vector.h" and use the test harness below to test your class
// testVector.cpp #include "vector.h" #include
int main() { vector
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
