[gameprogrammer] Re: General Purpose Double Linked List Class

Hi,

The STL list provides all of the functionality that you need. You do not really need to "wrap" it with an outside class because the STL list *is* a general purpose list.

Also, when using C++ it's generally not a good idea to store void pointers in your list as you need to make sure you type cast them before you delete etc etc. void pointers are a useful C thing, but there are safer alternatives in C++ (such as templates!!).

Instead have several list in your game on for each type, i.e one for enemies, one for projectiles etc.

class GameObjectManager{

public:

std::vector< Enemy* > vecEnemies;
std::vector< Projectile* > vecProjectiles;
etc ...


};


I also advise that you use the "vector" class instead of the list class, for faster access speed.


If you must store void pointers and wrap the class, then it might be better to subclass it instead, although if you plan on replacing the class with something that is non-STL based this would cause a problem later an containment is better in that case.

class MyList : public std::vector<void*>{

public:

};


Or even (i think this is correct syntax):


template<T> class MyList : public std::vector<T>{

public:

};


Another point is that C uses pointers to pointers in C++ it is usually better practice to use a reference to a pointer:


bool DoSometingWithPointer( int*  &myIntPtr);


Hope this helps.

- Tom


Hello !



I want to use STL to create a
general purpose linked list class,
that can be used in games or other
apps.

As i never used STL before,
is this way to use it correct ?

Thanks.



CU




---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: