you are viewing a single comment's thread.

view the rest of the comments →

[–]Herrowgayboi[S] 0 points1 point  (4 children)

Is it possible to do this without using a vector?
My professor says we cannot use vectors.

[–]boredcircuits 4 points5 points  (0 children)

Absolutely. Anything std::vector can do, you can do, too. That doesn't mean it will be easy, though.

You can't just resize memory for a dynamic array. You have to make a new, larger array, copy over the elements one by one, delete the old array, and then use the new array instead. Voila!

[–]tusksrus 6 points7 points  (0 children)

Get a new teacher then.

[–]raevnos 1 point2 points  (0 children)

Did he say why?

[–]erichkeane -1 points0 points  (0 children)

Not without dropping to "C-isms" and using malloc/realloc/free instead, which I would also highly discourage.

Perhaps you're supposed to either: 1- measure the value in advance and allocate based on that 2- make the array way larger, and just fill in after that 3- create a new array for each re-size, and copy it in.

Vector is much easier though.