我正在尝试将boost::shared_ptr
与async_read_until
一起使用,但无法使其正常运行。这是我的简化代码:
头
boost::asio::io_service io_service;
typedef boost::shared_ptr<boost::asio::serial_port> serial_port_ptr;
serial_port_ptr serial_port;
boost::asio::streambuf response_data;
char delimiter = '\n';
boost::system::error_code error;
连接
serial_port = serial_port_ptr(new boost::asio::serial_port(io_service));
serial_port->open("/dev/ttyS0", error);
读
boost::asio::async_read_until(
serial_port.get(), response_data, delimiter,
boost::bind(
&serial_comm::data_received,
this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
);
我得到的错误是no type named 'type' in 'struct std::enable_if<false, void>'
。谢谢。
答案 0 :(得分:1)
您已提供指针作为boost::asio::async_read_until
的输入而非参考。它应该像这样重写:
boost::asio::async_read_until(
*serial_port, response_data, delimiter,
boost::bind(
&serial_comm::data_received,
this, boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred
)
);