samedi 20 janvier 2018

How do I increase the size of an array that has been initialized as a data member of a class?

I need your advice on how to increase the size of the array v initialized in:

class Vector {

 private:
     int capacity=100;
     int v[100];
     int size=0;
 public:
     void push_back(int item);

};

I want to double the size of the array in the implementation of the member function push_back if size = capacity. If I set v[2*capacity] in my implementation of the member function, I will receive a compiler error. How do I resolve this issue? Thank you all for your help.

Aucun commentaire:

Enregistrer un commentaire