64,648
社区成员
发帖
与我相关
我的任务
分享
#include <boost/bind.hpp>
#include <boost/system/error_code.hpp>
#include <string>
template<typename Handler1, typename Handler2>
void two_handler_test_func(const char* p1, const char* p2, Handler1 handler1, Handler2 handler2)
{
handler1(boost::system::error_code());
handler2(boost::system::error_code());
}
class MyTestClass
{
public:
template<typename Handler>
void test_func(const std::string& p1, const std::string& p2, Handler handler)
{
two_handler_test_func(p1.c_str(), p2.c_str(),
boost::bind(&MyTestClass::handle_test_func1<Handler>, this, _1, handler),
boost::bind(&MyTestClass::handle_test_func2, this, _1, 2));
}
private:
template<typename Handler>
void handle_test_func1(const boost::system::error_code& ec, Handler handler)
{
handler(ec);
}
void handle_test_func2(const boost::system::error_code& ec, int b)
{}
};
void command_listen_finished(const boost::system::error_code& ec, int i)
{}
void command_listen_finished2(const boost::system::error_code& ec)
{}
class TestCallback
{
public:
TestCallback(int i)
:m_i(i)
{}
void operator()(const boost::system::error_code& ec)
{}
private:
int m_i;
};
int main()
{
MyTestClass testClass;
testClass.test_func("abc", "def", boost::bind(command_listen_finished, _1, 1));
//testClass.test_func("abc", "def", command_listen_finished2);
//testClass.test_func("abc", "def", TestCallback(1));
return 0;
}