Dynamic Array Allocation, In C++
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...
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
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
April 17, 2001 10:40 PM
but that will just create an array of integer pointers (an array of arrays)
April 17, 2001 10:41 PM
ok nevermind disregard that last post - sorry Absolution, you are right
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement