Mail Archives: djgpp/1998/04/14/10:34:08
You have 4 options:
1) Just don't let the user put in more than 10
2) Remove unused objects from the list if it gets to big
3) Use a linked list as already mentioned.
4) Malloc, realloc, free.
C++ doesn't have a realloc equivalant (oh no...) to new and delete. Use C
routines instead.
Object **objects;
objects = malloc(sizeof(Object*) * objectsneeded);
for (int i = 0; i < objectsneeded;i++)
objects[i] = new Object;
// If you need more, realloc it.
objects = realloc(objects, sizeof(Object*)*newobjectsneeded);
You will need to do some casting to get rid of C++ warnings, but I left them out
so you can read this.
--
"DeHackEd"
EMail address not given out due to low-life spammers.
- Raw text -