Advertisement

Dynamic Array Allocation, In C++

Started by April 17, 2001 09:55 PM
3 comments, last by Galileo430 23 years, 9 months ago
Ok, I need a way to allocate a array of longs dynamicly. However whenever I compile mine.. I get a error cause it is dynamic. I get error C2540: non-constant expression as array bound Anyway around this error?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
either use an STL template, or just use malloc, realloc, and free
Advertisement
You should probably post some code if you want more specific help, but if you want to allocate an array dynamically you just use the new word as so:

int size=SOME_NUMBER;

int *an_array = new int[size];

Where SOME_NUMBER is determined dynamically (i.e. from user input, file input, etc...). And if you no longer need this array you can free the memory as so:

delete[] an_array;

Abs
but that will just create an array of integer pointers (an array of arrays)
ok nevermind disregard that last post - sorry Absolution, you are right

This topic is closed to new replies.

Advertisement