diff --git a/examples/snake/src/main.cpp b/examples/snake/src/main.cpp index 246565b..4c68b50 100644 --- a/examples/snake/src/main.cpp +++ b/examples/snake/src/main.cpp @@ -248,8 +248,7 @@ public: } void OnCollide(std::shared_ptr entity) { - std::shared_ptr shared = dynamic_pointer_cast(entity); - if (shared) { + if (std::shared_ptr shared = std::dynamic_pointer_cast(entity); shared) { shared->Relocate(); BodyPiece piece{ sf::RectangleShape(sf::Vector2f(15, 15)), sf::Vector2i(0, 0) }; diff --git a/include/simpleengine/entity.h b/include/simpleengine/entity.h index c07fd2a..1c2616b 100644 --- a/include/simpleengine/entity.h +++ b/include/simpleengine/entity.h @@ -40,7 +40,7 @@ namespace simpleengine { template bool HasComponent() const { for (std::shared_ptr comp : components) { - if (dynamic_cast(comp.get())) { + if (std::dynamic_pointer_cast(comp)) { return true; } } @@ -51,8 +51,8 @@ namespace simpleengine { template std::shared_ptr GetComponent() const { for (std::shared_ptr comp : components) { - if (dynamic_cast(comp.get())) { - return dynamic_pointer_cast(comp); + if (std::shared_ptr dyn_comp = std::dynamic_pointer_cast(comp); dyn_comp) { + return dyn_comp; } }