I recognize the questions title is a bit vague, so thanks for at least reading it 😉
My situation is this: I have got a set of classes CommandA, CommandB, … derived from a common pure abstract base class ICommand. Now I need to keep instances of those derived classes in some kind of container but with the restirction that only one of each derived type should be allowed inside the container at any time. Instead when an item of already present derived type is inserted into the collection replacing the existing instance with the new one would occur.
Furthermore there is the need to remove a item from the collection based on its type.
I assume this would require some sort of type-identification at runtime. I have ruled out Runtime-Type-Identification as provided by the C++ compiler because we might at some point required to compile the project on (yet unknown) older compilers. Most witty template tricks thus probably also out of the game. But frankly I still would highly appreciate to not assign some numerical identfier to my derived classes by hand…
I am grateful for every hint on the issue.
Thanks alot in advance,
Arne
If you cannot use template or RTTI you can do something like this
You can use the address of static variable per class as their typeid