Por que o dynamic_cast é maligno ou não? Devo usar dynamic_cast neste caso?
Alguns dizemthe use of dynamic_cast often means bad design and dynamic_cast can be replaced by virtual functions
dynamic_cast
considerado design ruim?Suponha que eu tenha o nome da funçãofunc(Animal* animal, int animalType)
, a implementação em func é como:
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. */
}
Neste caso, é um uso adequado dedynamic_cast
?