I have a list of pointers to objects. These objects have nothing in common (i.e. no common base class); for better understanding: It is a list of objects that lie under the mouse cursor in a GUI.
Now I would like to know what kind of object it is. A node, a node handle, a line segment, a tag, and so on. However I cannot use typeid(*ptr) since ptr is a const void*.
Any solution for this? Can I force the usage of typeid since I know that the pointers always point to objects and not to mere values? Or is there no way around adding some fake common base class?
(edit: Currently I’m doing it that way that I store a struct in the list which additionally stores the type of the object (as enum). Maybe I should change this to store a type_info object …)
For a technical solution, not considering design level, use a
std::mapor hash table (whatever) to associate the untyped pointers with type descriptors or typed pointers, of course before the user starts using the mouse.At a higher level, the void* pointers are just ungood.
It would be best to fix the design instead of employing a kludge like the
std::map.Cheers & hth.