Archived

This topic is now archived and is closed to further replies.

Fast pointer storage

This topic is 5812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites