I want to map pointer to integer for purpose of serialization. The pointers may be of different types and may point to polymorphic objects possibly using multiple inheritance. I need to query the map to know if the pointer is stored in it and if it is, then what is the associated integral value.
What is the correct way to do it?
The simple way of map<void*, int>
that I thought of would not work because operator <
is not defined for arbitrary pointers. Or is that not a problem on common systems?
Another solution would be to have a vector<void*>
. But this would require to loop over all pointers stored in and I am not sure if the casting to void *
would not break the operator ==
for objects using inheritance.