Fast pointer storage

Started by
5 comments, last by Biberpelztrompete 22 years, 3 months ago
Hey, how do I store pointers, so I can access them quickly ? I created a linked list. Then I derived my class ( class UNIT ) from this linked list so I can store a large number of UNITs. That works so far. The next was that I wanted to make a list of selected units. I can''t use a linked list again, cause it would overwrite the first one. MFC offers a class called CList, but what I heard is that MFC should never ever be used in DirectX games. Though it would be good because it would ease pointer management a lot. Furthermore I dont understand the template stuff. CList< what goes here ?, and here ?> SelUnits(100); thx for your help
Advertisement
I''ve done it by just making a array of pointers.
UNIT *SelectedUnits[50];
It just limits how many units you can select at once in this case 50.
"I can''t use a linked list again, cause it would overwrite the first one."

I don''t understand what you mean here. You can have as many linked lists as you want.
I derived the the pointer to the next element. So I have only one pointer to the next object. If I add the object to a second linked list, the pointer to the next / previous element will be overwritten by the next SELECTED one.
I know it''s a little difficult to understand.
Do you know anything about CList ?
If you would like to use a linked list data structure without coding one yourself (and not using mfc''s CList) then you can use the standard template library. You can read about it here: http://www.cs.rpi.edu/projects/STL/htdocs/stl.html

Basically you would do something like this to make a list of ''UNIT''''s...

std::list mylistname;
UNIT myunit;
mylistname.push_front( myunit );

For more information about functions you can use on lists... there is a reference here:

http://www.dinkumware.com/htm_cpl/list.html

Was zum Teufel ist denn eine "Biberpelztrompete",
hört sich ziemlich barbarisch an :-)
(hey, Biber stehen unter Naturschutz!)
Echt toll ich hatte gehofft du antwortest auf meine Frage ...
:-)

Klar stehe ich unter Naturschutz. Ich werde Tag und Nacht gnadenlos gejagt !

This topic is closed to new replies.

Advertisement