[quote name='Ravyne' timestamp='1328715503' post='4910923']
If you want to hold both GridTile and UITile in the same Grid instance, then you have to use base class pointers like everyone has been saying (there are other non-standard "hacks" you could do, but are tricky and subject to a lot of caveats, so I won't go into that).
GridTiles and UiTiles will not be stored together in the same Grid instance. As a quick aside though, was I correct in thinking that there is no way to tell if a base pointer is pointing to a base or derived object without some sort of ID field in the base class?
Back to the main point however. Yes that's correct,
just one type of tile will be stored per Grid instance.
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I'll describe the overall problem to give an idea of what I'm attempting. Basically I'm making my own basic user interface for a 2D map editor. The interface will consist of various windows/panels that can be dragged about the screen. I refer to these as UiContainers. The containers have within them various types of UiElement[/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
, such as buttons, sliders and the like.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I had planned to split up the OpenGL window using a 2D grid to minimise collision detection tests between the mouse and the various UiWindows floating about the screen. The idea was that the tiles in this big grid would contain pointers to the UiWindows. As the windows would move about the screen, so the pointers in the big grid would be updated.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
Once it had been established which UiWindow was in the same tile as the cursor, further collision detction could be conducted on this single UiWindow to see which elements of it may be being controlled/clicked on by the mouse. I was going to use another grid to subdivide each UiWindow so we wouldn't have to check each UiElement on the window in question. As such these smaller grids (made ofUiTiles) would contain pointers to the buttons/sliders contained within them.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I guess because a 2D regular grid is such a commonly used thing I thought it would be best to have a generic Grid class that could be further specified in other classes. The GridTile for example only has a midpoint and has no real use save for providing a base class to inherit from for more specific grids. [/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
In short the UiTile would have a pointer to any possible ui elements for an individual ui wondow.[/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
I've attached an image incase I haven't explained it very well. [/font]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]
Thanks for your help so far, very useful stuff and it's much appreciated.[/font]
[/quote]
There is and there isn't when you turn RTTI on the runtime can tell you which type it is, without it there is no way to find out. But you usually don't care about it because the base class defines the public interface for what you want to do. You can override the functions in a derived version and in those you can actually access your derived members as well.