dynamically expanding an array in c++
Hey,
I've got this pointer that I want to point to an array of pointers of length X. This array may get full so I may want to create a new one of length 2 * X and copy all the stuff from the original one into this new one. I'm doing this in C++ and whenever I declare the array... void* asdf[ X ]; I get an error complaining that X isn't constant. So, I've been trying to work the "const" in there but I still can't get through this one. Thanks, mj |
Have you tried looking at vectors? I don't know how common they are in C++ or if there are better alternatives, but it holds a resize() function that seems to do all the work for you.
|
|
you need to use "new"
|
Re: dynamically expanding an array in c++
Quote:
or you can write in c and compile with gcc which allows non-constant array declarations. |
All times are GMT -5. The time now is 07:09 AM. |