Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dynamic Array Allocation, In C++

Started by Galileo430 Apr 17, 2001 at 9:55 PM 3 replies 300+ views
Original Post
Galileo430
Galileo430
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...
Absolution
Absolution
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.