This may sound like a dumb question, but does c/c++ have a ReDim equivalent?
Perhaps, see realloc(). ReDim is simply a keyword which does some work under the hood. "create/copy/delete"
You need to create a new array of the desired size, copy all your data in, and remove the old array.
You could make a ReDim-esque function.
template < typename T > ReDim( T*& p, size_t oldsize, size_t newsize ) {
T* newp = new T[ newsize ];
memcpy( newp, p, oldsize );
delete[] p;
p = newp;
}
// ...
char* lpStr = new char[256];
ReDim< char >( lpStr, 256, 512 );
Code is untested, probably contains bugs. But I hope you get the idea.
Yes I do. Thanks. :)
Or, if you're using a vector, you can use the resize() function.