title: Initialize Boost shared_ptr in constructor
body: <p>I have a class, which has a<code>boost::asio::io_service</code> object. I want this object stored in a <code>boost::shared_ptr</code>.</p>
  
  <p>So my header looks like this ( I got rid of any unnecessary code so it doesn't distract )</p>
  
  <pre><code>class CommandDispatcher
  {
  private:
      boost::shared_ptr&lt;boost::asio::io_service&gt; m_ioservice;
  public:
      CommandDispatcher();
  };
  </code></pre>
  
  <p>When I now create an object of <code>CommandDispatcher</code>I want that an <code>io_service</code> object to be initialized for the pointer. Now I'm not quite sure how to do this. I looked up two differentsolutions but only one is working and I'm not quite sure if it's a nice one. But see for yourself:</p>
  
  <pre><code>CommandDispatcher::CommandDispatcher()
  {
      m_ioservice.reset(new boost::asio::io_service);            // this actually works
      //m_ioservice = boost::make_shared&lt;boost::asio::io_service&gt;
      //    (new boost::asio::io_service);                     // this doesn't work
  }
  </code></pre>
  
  <p>So the <code>reset</code> call is working, but  I think this one is actually to reassign the pointer. So it is <em>not wrong</em> to use it but it doesn't seem like the nicest solution to me.
   The suggestion for the <code>make_shared</code> call I found in another question. But this one just won't work for me ( I implemented it as described in the official boost example ). I get </p>
  
  <p><code>/usr/local/include/boost/smart_ptr/make_shared.hpp:189: error: invalid conversion from ‘boost::asio::io_service*’ to ‘size_t’</code></p>
  
  <p><code>/usr/local/include/boost/smart_ptr/make_shared.hpp:189: error:   initializing argument 1 of ‘boost::asio::io_service::io_service(size_t)’</code></p>
  
  <p>I'm not quite sure how to do this now, which would be the best way ( maybe there is a complete other option to do it ). Or maybe I'm doin it right, but I'm gettin something with the <code>io_service</code>wrong.</p>
  
  <p>Hope this question hasn't been already here in this way ( I looked up some old question, but no answer seemed to fit for me ).</p>