Some say the use of dynamic_cast often means bad design and dynamic_cast can be replaced by virtual functions
- why is the use of
dynamic_cast
considered bad design? Suppose I have I function name
func(Animal* animal, int animalType)
, the implementation in func is like:bool func(Animal* animal, int animalType) { ... /* Animal is the base class of Bear, Panda, Fish .... dynamic_cast animal to real animals(Bear, Panda, Fish...) according to animalType. Do some processing with this specific type of animal, using its additional information beyond base class Animal. */ }
Is this case a proper use of dynamic_cast
?