Problems Expanding an Array in C++

▼魔方 西西 提交于 2019-12-02 00:09:01

You need to pass oldarray as a reference: orgType *& oldarray. The way it's currently written, the function will delete the caller's array but will not give it the newly allocated one, causing the crash.

Better yet, use std::vector instead of reimplementing it.

The C++ standard library already has functionality written to do this.

Use the std::vector container.

Looks like you are modifying the pointer oldarray to point to the new array, but remember in the function that's just a copy and won't affect the variable you passed in. You probably need to pass a reference to a pointer if you want to do it this way.

And indeed, std::vector does this for you anyway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!