Author | Message | Time |
---|---|---|
Eli_1 | This may sound like a dumb question, but does c/c++ have a ReDim equivalent? | July 29, 2004, 5:27 AM |
Eibro | 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. [code]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]Code is untested, probably contains bugs. But I hope you get the idea. | July 29, 2004, 5:50 AM |
Eli_1 | Yes I do. Thanks. :) | July 29, 2004, 4:36 PM |
K | Or, if you're using a vector, you can use the resize() function. | July 29, 2004, 8:27 PM |