title: How to create a serial port by boost::asio and shared_ptr
body: <p>At first, I'm not an expert c++ programming and my question might be very elementary.</p>
  
  <p>I am trying to use boost asio to access serial port and using shared_ptr to prevent memory leak. I searched some sample codes but for me, simply many of them don't work.</p>
  
  <p>my code is as follow:</p>
  
  <p>SerialPortConnection.cpp:
  </p>
  
  <pre><code>#include "SerialPortConnection.h"
  SerialPortConnection::SerialPortConnection( std::string port_name_init, int baud_rate_init,
          boost::asio::serial_port_base::character_size        charSize_init,
          boost::asio::serial_port_base::stop_bits             stopBit_init,
          boost::asio::serial_port_base::parity                pariy_init,
          boost::asio::serial_port_base::flow_control          flowControl_init)        :
          port_name(port_name_init),
          baud_rate(baud_rate_init),
          charSize(charSize_init),
          stopBit(stopBit_init),
          pariy(pariy_init),
          flowControl(flowControl_init)
  {
  port = boost::shared_ptr&lt;serial_port_ptr&gt;( new boost::asio::serial_port );
  }
  SerialPortConnection::~SerialPortConnection()
  {
      //dtor
  }
  </code></pre>
  
  <p>SerialPortConnection.h:
  </p>
  
  <pre><code>#ifndef SERIALPORTCONNECTION_H
  #define SERIALPORTCONNECTION_H
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;memory&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/asio/serial_port.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/make_shared.hpp&gt;
  //using namespace::boost::asio;
  class SerialPortConnection
  {
  public:
      SerialPortConnection( std::string port_name_init, int baud_rate_init,
                            boost::asio::serial_port_base::character_size        charSize000_init,
                            boost::asio::serial_port_base::stop_bits             stopBit000_init,
                            boost::asio::serial_port_base::parity                pariy000_init,
                            boost::asio::serial_port_base::flow_control          flowControl_init );
      virtual ~SerialPortConnection();
  private:
      std::string port_name;
      int baud_rate;
      boost::asio::serial_port_base::character_size        charSize;
      boost::asio::serial_port_base::stop_bits             stopBit;
      boost::asio::serial_port_base::parity                pariy;
      boost::asio::serial_port_base::flow_control          flowControl;
      boost::asio::io_service io;
      typedef boost::asio::serial_port* serial_port_ptr;
      boost::shared_ptr &lt; serial_port_ptr &gt; port;
  };
  #endif // SERIALPORTCONNECTION_H
  </code></pre>
  
  <p>Compiler creates compile error:</p>
  
  <pre><code>||=== Build: Debug in test-1 (compiler: GNU GCC Compiler) ===|
  /home/mkh/cb-codes/test-prjs/test-1/src/SerialPortConnection.cpp||In constructor ‘SerialPortConnection::SerialPortConnection(std::__cxx11::string, int, boost::asio::serial_port_base::character_size, boost::asio::serial_port_base::stop_bits, boost::asio::serial_port_base::parity, boost::asio::serial_port_base::flow_control)’:|
  /home/mkh/cb-codes/test-prjs/test-1/src/SerialPortConnection.cpp|17|error: no matching function for call to ‘boost::asio::basic_serial_port&lt;&gt;::basic_serial_port()’|
  /usr/include/boost/asio/basic_serial_port.hpp|147|note: candidate: boost::asio::basic_serial_port&lt;SerialPortService&gt;::basic_serial_port(boost::asio::basic_serial_port&lt;SerialPortService&gt;&amp;&amp;) [with SerialPortService = boost::asio::serial_port_service]|
  /usr/include/boost/asio/basic_serial_port.hpp|147|note:   candidate expects 1 argument, 0 provided|
  /usr/include/boost/asio/basic_serial_port.hpp|126|note: candidate: boost::asio::basic_serial_port&lt;SerialPortService&gt;::basic_serial_port(boost::asio::io_service&amp;, const native_handle_type&amp;) [with SerialPortService = boost::asio::serial_port_service; boost::asio::basic_serial_port&lt;SerialPortService&gt;::native_handle_type = int]|
  /usr/include/boost/asio/basic_serial_port.hpp|126|note:   candidate expects 2 arguments, 0 provided|
  /usr/include/boost/asio/basic_serial_port.hpp|105|note: candidate: boost::asio::basic_serial_port&lt;SerialPortService&gt;::basic_serial_port(boost::asio::io_service&amp;, const string&amp;) [with SerialPortService = boost::asio::serial_port_service; std::__cxx11::string = std::__cxx11::basic_string&lt;char&gt;]|
  /usr/include/boost/asio/basic_serial_port.hpp|105|note:   candidate expects 2 arguments, 0 provided|
  /usr/include/boost/asio/basic_serial_port.hpp|85|note: candidate: boost::asio::basic_serial_port&lt;SerialPortService&gt;::basic_serial_port(boost::asio::io_service&amp;, const char*) [with SerialPortService = boost::asio::serial_port_service]|
  /usr/include/boost/asio/basic_serial_port.hpp|85|note:   candidate expects 2 arguments, 0 provided|
  /usr/include/boost/asio/basic_serial_port.hpp|69|note: candidate: boost::asio::basic_serial_port&lt;SerialPortService&gt;::basic_serial_port(boost::asio::io_service&amp;) [with SerialPortService = boost::asio::serial_port_service]|
  /usr/include/boost/asio/basic_serial_port.hpp|69|note:   candidate expects 1 argument, 0 provided|
  ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
  </code></pre>
  
  <p>I've tried various solutions. for example I added this one to SerialPortConnection.h:</p>
  
  <p>boost::asio::serial_port    port0;</p>
  
  <p>but also it doesn't work. It actually leads to another compile error.
  Now I need to know how to create a serial port with shared_ptr. </p>
  
  <p>Thank you,</p>