Yes, static_cast OK in this case and the right thing to use.
I have to ask why you do not store classA* pointers in the first place. If you want to place the pointers of derived classes into it, then beware , before you put them on the map, you need to raise or not convert (implicitly or explicitly) the pointers of derived classes to classA* .
But even if you put class pointers on the map as well, a base class pointer will suffice, because a derived class pointer is implicitly converted to a base class pointer.
The reason void * is used is because hold is a member of the class definition in the header used by some cpp files that don't know what class A is.
This can be a good reason to prevent overlay violations.
I would have to include the heading of classA definitions in these cpp files, which cannot be executed for many reasons.
This is most likely not necessary in your case. Adequate declaration. If the header knows what fits on the map but just wants to avoid including additional headers, this is the way to go.
source share