using dynamic_cast instead