From 9afa9c4e97faa9a6d7e6089ec1f822047738fdec Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Sat, 14 Mar 2020 17:30:51 +0300 Subject: Store Bot::_eventBroadcaster in unique ptr. Fixes #131. --- include/tgbot/Bot.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/tgbot/Bot.h b/include/tgbot/Bot.h index 49131d3..ac5d096 100644 --- a/include/tgbot/Bot.h +++ b/include/tgbot/Bot.h @@ -20,7 +20,10 @@ class TGBOT_API Bot { public: explicit Bot(std::string token, const HttpClient& httpClient = _getDefaultHttpClient()) - : _token(std::move(token)), _api(_token, httpClient), _eventHandler(_eventBroadcaster) { + : _token(std::move(token)) + , _api(_token, httpClient) + , _eventBroadcaster(std::make_unique()) + , _eventHandler(getEvents()) { } /** @@ -41,7 +44,7 @@ public: * @return Object which holds all event listeners. */ inline EventBroadcaster& getEvents() { - return _eventBroadcaster; + return *_eventBroadcaster; } /** @@ -59,7 +62,7 @@ private: const std::string _token; const Api _api; - EventBroadcaster _eventBroadcaster; + std::unique_ptr _eventBroadcaster; const EventHandler _eventHandler; }; -- cgit v1.2.3