Archived

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

storing items

This topic is 5340 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

i''m designing a GUI for my game which is composed of different classes, all derived from CGUIobject i want to store them into an array (ex: { CGUIbutton x, CGUItextbox t, etc } like a collection in VB how can i store the different classes into an array and at runtime determine for each what type of class it is so i can call it''s specific functions

Share this post


Link to post
Share on other sites
You have essentially two options here, and both involve storing a collection (eg a vector) of CGuiObject*. You could either:
(1) Use C++ RTTI to determine whether each object is of a particular type, and act accordingly, or
(2) [This is what MFC does] Create your own RTTI system, which can tell you exactly what type it is, and act accordingly.

I would recommend option 1, as 2 is a whole lot of effort (believe me, I''ve done it...)

Share this post


Link to post
Share on other sites
Couldn''t you just have an array of the base class and use the typeid keyword to determine what class the baseclasspointer really is pointing to?


____________________ ____ ___ __ _
Enselic''s Corner - My site. Go test my game Spatra and see if you can beat it onto the Official Spatra Top 10.
CodeSampler.com - Great site with source for specific tasks in DirectX and OpenGL.

Share this post


Link to post
Share on other sites