65,189
社区成员




#include <stdio.h>
#include <sys/wait.h>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/bind.hpp"
#include "boost/functional.hpp"
using namespace std;
using namespace boost;
using namespace boost::posix_time;
typedef void (*Callback)();
void Fun(int x, Callback cb)
{
cout << x << endl;
cb();
}
void RealCallback()
{
cout << "Real Call Back" << endl;
}
class TestCase
{
public:
void TCCallback()
{
cout << "TC Call Back" << endl;
}
void Run()
{
Fun(5,boost::bind(&TestCase::TCCallback, this));
}
};
int main(int argc, const char *argv[])
{
TestCase tc;
tc.Run();
return 0;
}
boost::function<void()> f = boost::bind(&TestCase::TCCallback, this);
typedef void (*Callback)(); \\这个是函数指针方式,别混淆了
class TestCase
{
public:
static void TCCallback()
{
cout << "TC Call Back" << endl;
}
void Run()
{
Fun(5, TCCallback);
}
};
class TestCase
{
public:
void Run()
{
Fun(5, RealCallback);
}
};