首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

boost:bind后解决办法

2012-07-16 
boost::bind后C/C++ codevoid StaticFunc(){std::coutHello! This is boost::binds first STATIC_FUNC

boost::bind后

C/C++ code
void StaticFunc()  {      std::cout<<"Hello! This is boost::bind's first STATIC_FUNCTION bind"<<std::endl;  }  class BindedObject  {  public:      BindedObject(int _data)          : mData(_data){}  public:      void show()      {          std::cout<<"Hello! This is boost::bind's first MEMBER_FUNCTION bind"<<std::endl;      }      void showData()      {          std::cout<<"mData = "<<mData<<std::endl;      }  private:      int mData;  };  int _tmain(int argc, _TCHAR* argv[])  {      // 绑定全局函数并调用       boost::bind(&StaticFunc)();      // 绑定成员函数并调用(固定了操作的对象)       boost::bind(&BindedObject::show, BindedObject(0))();      // 另一种绑定成员函数并调用(没有固定操作的对象,推荐)       boost::bind(&BindedObject::show, _1)(new BindedObject(0));  }已经bind了, bind 后,干嘛呢???


[解决办法]
// 绑定全局函数并调用
boost::bind(&StaticFunc)();
// 绑定成员函数并调用(固定了操作的对象)
boost::bind(&BindedObject::show, BindedObject(0))();
// 另一种绑定成员函数并调用(没有固定操作的对象,推荐)
boost::bind(&BindedObject::show, _1)(new BindedObject(0));
你这样是已经执行了呀。
一般是这么用:
void run(boost::function<void()> fun)
{
fun();
}
run(boost::bind(&StaticFunc));
 
[解决办法]
恩 那个占位符还是传的对象
http://blog.csdn.net/Solstice/article/details/3066268 有篇blog可以看看
[解决办法]
boost:function和boost:bind一起看。 单看没啥意义。

热点排行