storing items

Started by
1 comment, last by Ilici 20 years, 11 months ago
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
Advertisement
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...)
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.
[s]--------------------------------------------------------[/s]chromecode.com - software with source code

This topic is closed to new replies.

Advertisement