How to implement vector in C++.
Utilisateur anonyme
You have an object with three attributes: size (number of elements), capacity, and the array. You will probably want to use template to keep everything generic: template Also, you will have to overload some operators. Subscripting is the most important. When you insert an element, check the size. If the size and the capacity are the same, you will have to use realloc and double the size. In the constructor use malloc. This is how to resize: vector->data = realloc(vector->data, sizeof(int) * vector->capacity