Почему dynamic_cast является злом или нет? Должен ли я использовать dynamic_cast в этом случае?
Некоторые говорятthe use of dynamic_cast often means bad design and dynamic_cast can be replaced by virtual functions
dynamic_cast
считается плохим дизайном?Предположим, у меня есть имя функцииfunc(Animal* animal, int animalType)
реализация в func выглядит так:
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. */
}
Это случай правильного использования?dynamic_cast