I have class Base and classes Derived_1, Derived_2 ...
I need derived classes to have an id. Those ids are used for further lookups et
C++11 solves this by providing std::type_index, in , which is a copyable, comparable and hashable object constructed from a std::type_info object that can be used as the key in associative containers.
(The implementation is fairly simple, so even if you don't have C++11 yourself, you could steal the implementation from, say GCC 4.7, and use that in your own code.)
#include
#include
#include
typedef std::unordered_map tmap;
int main()
{
tmap m;
m[typeid(main)] = 12;
m[typeid(tmap)] = 15;
}