类从这里实例化错误c ++

我试图创建一个类,它将读取和解析来自串口的数据,但是我不断收到一个实例化的错误,我不知道为什么。 这个类需要一个串口和它的io_service。 我正在使用boost。 我遇到了很多错误,但我认为它是因为它的累积性(我认为,我不确定这是否正确)。 这是第一个:

从/usr/include/boost/bind.hpp:22:0包含的文件中,从../Sources/Magnetic Compensator Core.cpp:17:

/usr/include/boost/bind/bind.hpp:在'boost :: _ bi :: result_traits&,const boost :: system :: error_code&,unsigned int'>''的实例化中:/ usr / include / boost / bind / bind_template .hpp:15:48:从'boost :: _ bi :: bind_t&,const boost :: system :: error_code&,unsigned int'实例化,boost :: _ bi :: list4,boost :: reference_wrapper>,boost :: arg < 1>,boost :: arg 2>''

这是这个类的代码:

class mag_serial
{
bool data_available;
boost::asio::serial_port& ser_port;
boost::asio::deadline_timer timeout;
char my_buffer[1];
std::string str;
std::string st;


void read_callback(bool& data_available, boost::asio::deadline_timer& timeout, const boost::system::error_code& error, std::size_t bytes_transferred)
        {

            data_available = true;
            if(str.length() > 1)
            {
            if (!(str.at(str.length() - 1) == temp))//&str.at(str.length() - 1) != "#")
            {
                str.append(my_buffer,bytes_transferred);
                if(str.at(str.length() - 1) == quit)
                {
                    cout << "I am quitting";

                            Stop();
                            ser_port.cancel();
                            ser_port.close();
                            return;
                }

                i++;
            }

            else if (str.at(str.length() - 1) == temp)
            {
                st = str;//.substr(1, str.size());

                // Processing Functions
            }
            }
            else
            {
                str.append(my_buffer,bytes_transferred);
                if(str.at(0) == quit)
                {
                    cout << "I am quitting";
                    Stop();
                            ser_port.cancel();
                            ser_port.close();
                            return;
                }
            }
            ser_port.async_read_some(boost::asio::buffer(my_buffer),
                boost::bind(&mag_serial::read_callback, boost::ref(data_available),
                        boost::ref(timeout),boost::asio::placeholders::error(),
                        boost::asio::placeholders::bytes_transferred()));
            data_available = true;
        }

        void wait_callback(boost::asio::serial_port& ser_port, const boost::system::error_code& error)
        {
            if (error)
            {
                // Data was read and this timeout was cancelled

                return;
            }

        }




public:
mag_serial(boost::asio::serial_port& ser_port, boost::asio::io_service& io_svc): ser_port(ser_port), timeout(ser_port.get_io_service()){}



void read_mag_serial_thread()
{
    bool data_available = false;

    ser_port.async_read_some(boost::asio::buffer(my_buffer),
            boost::bind(&mag_serial::read_callback, boost::ref(data_available),
                    boost::ref(timeout),boost::asio::placeholders::error(),
                    boost::asio::placeholders::bytes_transferred()));
    timeout.expires_from_now(boost::posix_time::seconds(1));
    timeout.async_wait(boost::bind(&mag_serial::wait_callback, boost::ref(ser_port),boost::asio::placeholders::error()));

    io_svc.run();

    if(!data_available)
    {
        ser_port.close();
        cout << "ser_port was closed";
    }
}

};

这不会编译

ser_port.async_read_some(boost::asio::buffer(my_buffer),
                boost::bind(&mag_serial::read_callback, boost::ref(data_available),
                        boost::ref(timeout),boost::asio::placeholders::error(),
                        boost::asio::placeholders::bytes_transferred()));

成员函数mag_serial::read_callback需要绑定一个实例。

ser_port.async_read_some(
    boost::asio::buffer(my_buffer),
    boost::bind(
        &mag_serial::read_callback,
        this,
        boost::ref(data_available),
        boost::ref(timeout),
        boost::asio::placeholders::error,
        boost::asio::placeholders::bytes_transferred
    )
);

这是一个coliru,我没有试图修复格式。

链接地址: http://www.djcxy.com/p/60649.html

上一篇: Class Instantiated from here error c++

下一篇: How to serialize OpenCV Mat with boost XML archive