Possible Duplicate:
How do youreallocin C++?
I know that C++ arrays can be reallocated (expanded) using realloc() if memory has been allocated via malloc() or calloc(). My question is, how can I expand an array in C++ whose memory has been allocated via the new operator?
You can’t – that’s why in C++ you use
std::vector<>.If you wanted to do this, you’d have to allocate a new array (via
new), then copy the old items across (std::copyfor example), thendelete[]the previous array.Just use
std::vector– let it do all that stuff for you…