Skip to content

Instantly share code, notes, and snippets.

@drewxa
Last active February 27, 2018 08:24
Show Gist options
  • Save drewxa/dc9929cfe97b63f7bd31cf8ac97aed38 to your computer and use it in GitHub Desktop.
Save drewxa/dc9929cfe97b63f7bd31cf8ac97aed38 to your computer and use it in GitHub Desktop.
struct Object {
virtual void OnCollision(Object * other) = 0;
virtual ~Object() = default;
};
struct Ship : public Object { ... };
struct Asteroid : public Object { ... };
// отрефакторить функцию так, чтобы не использовались type_info, dynamic_cast и подобного
// должно масштабироваться на большое количество наследников Object
Ship::OnCollision(Object * o) {
if (dynamic_cast<Ship *>(o)) {
// ...
}
else if (dynamic_cast<Asteroid *>(o)) {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment