General linked-list-template for class objects
Posted on 2004-11-04
When making games i've been using linked lists to have dynamic class-instantiation, and this has worked very well, but in the long run, I feel it's too complicated having to cut and paste the code when making a list for another linked list. I've been looking at some alternatives, but I need some tips on what would suit me best.
What i need is a way to easily create a linked-list object that keeps track of all the list-objects i've created, as well as a way to easily loop through all the objects and perform some action on them.
I've considered using the STL list or vector-templates, but I seems like its not really what I want as I have to specify an object to add, rather than telling it to add an object for itself at the end of the linked list. (To me, the whole point with linked lists is being able to add objects dynamically without instantiating an object first)
The other alternative I thought about is making a class template for a general list-control. Then I can inherit from that class template, and make my own list-control with my own add-object-function and loop-through-objects function that lets me do the instantiating and usage of the objects.