boost中线程和function的疑问
问题请见代码中的注释
#include "stdafx.h"#include <boost//thread.hpp>#include <boost/bind.hpp>#include <boost/function.hpp>#include <iostream>using namespace std;void fun1(){ while(1) { cout << "fun1" << endl; boost::this_thread::sleep(boost::posix_time::millisec(50)); }}void fun2(long l1, long l2){ while(1) { cout << "l1=" << l1 << " l2=" << l2 << endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); }}long fun3(long l1, long l2, long l3){ while(1) { cout << "l1=" << l1 << " l2=" << l2 << " l3=" << l3 << endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); }}long fun4(long l1, long l2, long l3, long l4){ while(1) { cout << "l1=" << l1 << " l2=" << l2 << " l3=" << l3 << " l4=" << l4 << endl; boost::this_thread::sleep(boost::posix_time::seconds(1)); }}int main(int argc, char* argv[]){ boost::thread tr1(fun1); boost::thread tr2(fun2, 1, 2); boost::thread tr3(boost::bind(fun3, 1, 2, 3)); boost::function< void(void)> func4 = boost::bind(fun4, 1, 2, 3, 4); /* 1、为何这里写boost::function< long(long, long, long, long)> func4 = boost::bind(fun4, 1, 2, 3, 4);的时候 * 下面的boost::thread tr4(func4);就无法通过编译?注:我用的VS2008 * 2、上述两种写法有何区别?为何可以写参数模块可以写 void(void) 呢? */ boost::thread tr4(func4); tr1.join(); tr2.join(); tr3.join(); tr4.join(); return 0;}