From ce0d751890112f9c90b8fac63ac3f22b5f58bad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sat, 1 Jun 2024 16:06:32 +0200 Subject: [PATCH] Wrap game feature in shared pointer. --- src/game_features/igamefeatures.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/game_features/igamefeatures.h b/src/game_features/igamefeatures.h index ac76ae45..c625bfbf 100644 --- a/src/game_features/igamefeatures.h +++ b/src/game_features/igamefeatures.h @@ -145,19 +145,20 @@ class IGameFeatures * @return the feature of the given type, if one exists, otherwise a null pointer. */ template - T* gameFeature() const + std::shared_ptr gameFeature() const { // gameFeatureImpl ensure that the returned pointer is of the right type (or // nullptr), so reinterpret_cast should be fine here - return dynamic_cast(gameFeatureImpl(typeid(T))); + return std::dynamic_pointer_cast(gameFeatureImpl(typeid(T))); } public: virtual ~IGameFeatures() = default; protected: - virtual GameFeature* gameFeatureImpl(std::type_info const& info) const = 0; - virtual int unregisterFeaturesImpl(std::type_info const& info) = 0; + virtual std::shared_ptr + gameFeatureImpl(std::type_info const& info) const = 0; + virtual int unregisterFeaturesImpl(std::type_info const& info) = 0; }; } // namespace MOBase