|
malloc and new
i was wondering how you all feel about using malloc in C++ coding.
let's say i ask the user how many people there are in his neighborhood, and input int numberofNeighbors, for use with some neighbor class.
then i can malloc an array of pointers, and each time i make a new Neighbor, i can put the addy into the malloc-ed array, and re-get it without fiddling with a linked list.
anyone have a better way of doing this. that is to say a way that doesn't waste tons of memory, or force me to go through object references to other objects. this way lets me allocate exactly the right amount of space, no more, no less.
basically, is there a way to make a totally arbitrary array of pointers using "new"?
|