I have a class that has a boost::asio::io_service
. I want this object to be stored in boost::shared_ptr
.
So, my title looks like this (I got rid of any unnecessary code so that it does not distract)
class CommandDispatcher { private: boost::shared_ptr<boost::asio::io_service> m_ioservice; public: CommandDispatcher(); };
When I create the CommandDispatcher
object, I want the io_service
object to io_service
initialized for the pointer. Now I'm not quite sure how to do this. I looked at two different questions, but only one works, and I'm not quite sure if it is good. But see for yourself:
CommandDispatcher::CommandDispatcher() { m_ioservice.reset(new boost::asio::io_service);
So, the reset
call works, but I think it really does reassign the pointer. Therefore, you should not use it, but it does not seem like the best solution for me. A suggestion for calling make_shared
, which I found in another question. But that just won't work for me (I implemented it as described in the official promotion example). I get
/usr/local/include/boost/smart_ptr/make_shared.hpp:189: error: invalid conversion from 'boost::asio::io_service*' to 'size_t'
/usr/local/include/boost/smart_ptr/make_shared.hpp:189: error: initializing argument 1 of 'boost::asio::io_service::io_service(size_t)'
I'm not quite sure how to do it now, which would be best (maybe there is another option). Or maybe I'm doing it right, but I am getting something with an io_service
error.
I hope this question was no longer here (I raised some old question, but the answer was not like me).