Archived

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

aDasTRa

[a question about linked lists]

Recommended Posts

aDasTRa    122
i was thinking about this in my assembly class and was wondering how you would translate it to c++: for a linked list instead of having some kind of structure with the data and next pointer, you could just have a pointer to the address of the data, and the next pointer. why would you want to do this? linked two of anything together. i was thinking of making a parent class called ''node'', or something, and then just a void* inside to the data. eg class cNode { public: cNode *next; (void) *data; //other member data and methods }; would that work? the reason i want to do this is so i can link objects to one another. for example i could have a bullet object, and link to that a particle emitter. i could then link the bullet objects to a gun, which i could link to a character''s hand object, which is linked to the arm...etc. i know i could just use a parent class for most of this (and i do), but when it comes to things like particle systems or even sounds, i don''t want a huge all encompassing parent class if i don''t need it. <(o)>

Share this post


Link to post
Share on other sites
Kylotan    10008
Of course, people have been doing this for years. But it''s things like this that base classes and templates were invented to get rid of You lose type safety, you have to know what type the object is before you do anything with it, and so on. Generally a bad idea.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites