summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEgor Pugin <egor.pugin@gmail.com>2020-03-14 17:30:51 +0300
committerEgor Pugin <egor.pugin@gmail.com>2020-03-14 17:30:51 +0300
commit9afa9c4e97faa9a6d7e6089ec1f822047738fdec (patch)
tree2b3c3e82a03121401adba9a243328f542267334f
parent19f49b7a2f540a756ed9759b0fa5fb52bf73f20e (diff)
Store Bot::_eventBroadcaster in unique ptr. Fixes #131.
-rw-r--r--include/tgbot/Bot.h9
1 files 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<EventBroadcaster>())
+ , _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> _eventBroadcaster;
const EventHandler _eventHandler;
};