I found myself in a position where it seems I need to use dynamic_cast but I would like to avoid that. What I have is my base class called Sound and a bunch of derived object called PointSound, PlaneSound, etc. The problem is that from a different part of the program I have an stl map with pointers to different Sound objects which cound be PointSound, PlaneSound or whatever, and I need to have the actual type of the Sound. So for example I would do
But I want to avoid using dynamic_casts or having to enable RTTI due to performance issues. The only solution I could come up with is just plain horrible, I would create a virtual function in Sound called isPlaneSound() and would return a valid PlaneSound pointer if the Sound is in fact a PlaneSound. But that just horrible since I would have to do the same for each type and I code would be just horrible to maintain.Code:
Sound *currentSound = this;
PlaneSound *mySound = dynamic_cast<PlaneSound*>(currentSound); //currentSound is type Sound.
I hope someone can help me, thanks in advance.