Last active
February 27, 2018 08:24
-
-
Save drewxa/dc9929cfe97b63f7bd31cf8ac97aed38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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