C++: What is the proper way of resizing a dynamically allocated array?

后端 未结 4 784
谎友^
谎友^ 2021-01-03 01:59

In C, I would have done it using realloc.

In C++, one would normally consider using the STL vector class.

But how do I properly res

4条回答
  •  佛祖请我去吃肉
    2021-01-03 02:18

    By doing what vector and realloc do internaly: make a new, bigger array, copy the content of the old one, and destroy the old one.

提交回复
热议问题