Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic arrays possible?

Status
Not open for further replies.

ApJ

Technical User
Nov 16, 2001
8
0
0
DK
This is a user of borland C++ builder 5 begging :)
Is it possible to make an new array, with dynamic size, during runtime?

e.g:
void MyFunction(int NumOfelements)
{
int MyArray[NumOfElements];
}

This don't work, error msg:"E2313 Constant expression required".

As far as I know Builder say it isn't possible, but do anybody know a work-around?

I can't use #define, need somthing I can change during Runtime (and I can't make it work with #define either).

oh... a tiny example would be nice, I'm not 100% hardcore at this stuff :)
 
It's not possible with C/C++ at all the way it is written. Look at C++ STL vector, deque, list. They will provide you with the dynamic capability that you are looking for and then some (e.g. the ability to add/delete elements at either end of the list). James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
you can also do:

int* myArray;

myArray = new int[arraySize];
...

delete[] myArray;

Matt
 
First, sorry about the delay (my only HD broke down).

1000 x thanks, that was exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top