64,661
社区成员
发帖
与我相关
我的任务
分享
// testBoost.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
class AFun: public boost::enable_shared_from_this<AFun>
{
public:
//boost::function<void(boost::shared_ptr<AFun>&)> QueryCallBack;
typedef boost::function<void( boost::shared_ptr<AFun>&)> BTCALLBACK;
BTCALLBACK callback;
void print(){
std::cout<<"GGGGGGGGGGGGGGGGGGGGGGGGGGGG"<<std::endl;
}
void run(){
boost::shared_ptr<AFun> aFun = this->shared_from_this();
callback(aFun);
}
};
//typedef boost::function<void( boost::shared_ptr<AFun>&)> BTCALLBACK;
class BFun
{
public:
void BindTestFun(boost::shared_ptr<AFun>& aFun){
aFun->print();
}
void run(){
boost::shared_ptr<AFun> aptr(new AFun());
aptr->callback = boost::bind(&BFun::BindTestFun, *this, _1);
aptr->run();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
BFun b;
b.run();
return 0;
}