C++ 来自其他类的asio计时器

C++ 来自其他类的asio计时器,c++,boost,timer,boost-asio,C++,Boost,Timer,Boost Asio,我试试这个:。 但是空白打印在另一个类中。在main中调用函数时: t.async_wait(&class::print); 我有一个错误: 错误:必须使用“.*”或“->*”调用指向“boost::asio::detail::lvref()(…)”中成员函数的指针,例如“(…->*boost::asio::detail::lvref()”) 我不知道如何解决这个问题:s 您必须绑定对象实例,如:t.async_wait(boost::bind(&Class::print,this,_

我试试这个:。 但是空白打印在另一个类中。在main中调用函数时:

t.async_wait(&class::print);
我有一个错误:

错误:必须使用“.*”或“->*”调用指向“boost::asio::detail::lvref()(…)”中成员函数的指针,例如“(…->*boost::asio::detail::lvref()”)

我不知道如何解决这个问题:s


您必须绑定对象实例,如:t.async_wait(boost::bind(&Class::print,this,_1));或者,如果实例不是这个,则使用另一个指向类的(智能)指针。您可以使用引用,但这需要一个引用包装器来防止bind复制绑定参数:Class c; // ... t、 异步等待(boost::bind(&Class::print,boost::ref(c),_1))

我已经尝试过了,但我有一个错误:

error : 'void (class::*)(const boost::system::error_code&)' is not a class, struct, or union type typedef typename F::result_type type;

您需要处理print方法所需的参数。 大概是这样的: t->async_wait(boost::bind(&Class::print),这, boost::asio::占位符::错误); 看看这个教程

我试过了,但我有一个错误,我不明白

error : pointer to member type 'void (class::)(const boost::system::error_code&)' incompatible with object type 'windows'
     BOOST_MEM_FN_RETURN (get_pointer(u)->*f_)(b1);
                                        ^

您必须绑定对象实例,如:

t.async_wait(boost::bind(&Class::print, this, _1));
或者,如果实例不是
,请使用另一个(智能)指针指向
。您可以使用引用,但这需要引用包装器来防止bind复制绑定参数:

Class c;

// ...
t.async_wait(boost::bind(&Class::print, boost::ref(c), _1));

您必须绑定对象实例,如:

t.async_wait(boost::bind(&Class::print, this, _1));
或者,如果实例不是
,请使用另一个(智能)指针指向
。您可以使用引用,但这需要引用包装器来防止bind复制绑定参数:

Class c;

// ...
t.async_wait(boost::bind(&Class::print, boost::ref(c), _1));

您需要处理print方法所需的参数

大概是这样的:

t->async_wait(boost::bind(&Class::print, this,
      boost::asio::placeholders::error));

查看本教程

您需要处理print方法所需的参数

大概是这样的:

t->async_wait(boost::bind(&Class::print, this,
      boost::asio::placeholders::error));
看看这个教程