#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <vector>
#include <algorithm>
#include <functional>
#include <stdlib.h>
using namespace std;
using namespace boost; //function函数包装器
void mainC()
{
//atoi //char * to int
boost::function<int(char *)> fun = atoi;
cout << fun("") + fun("") << endl;
fun = strlen;
cout << fun("") + fun("") << endl;
cin.get();
} //函数包装器指定某个参数
void mainD()
{
boost::function<int(char *)> fun = atoi;
cout << fun("") + fun("") << endl;
fun = boost::bind(strcmp, "ABC", _1);
cout << fun("") << endl;
cout << fun("ABC") << endl;
cin.get();
} //类中有绑定函数
class manager
{
public:
//调用绑定的函数
void allstart()
{
for (int i = ; i < ; i++)
{
if (workid)
{
workid(i);
}
}
} //绑定调用
void setcallback(boost::function<void(int)> newid)
{
workid = newid;
} public:
//绑定一个函数
boost::function<void(int)> workid;
}; //worker类
class worker
{
public:
void run(int toid)
{
id = toid;
cout << id << "工作" << endl;
}
public:
int id;
}; void main()
{
manager m;
worker w; //类的成员函数需要对象来调用
//给manager类的成员函数绑定了一个默认的函数,以及对象
m.setcallback(boost::bind(&worker::run, &w, _1));
//调用
m.allstart();
cin.get();
}

4.bind绑定的更多相关文章

  1. jquery中bind()绑定多个事件

    bind()绑定事件 $(selector).bind(event,data,function): 参数event为事件名称(如"click,mouseover....."),da ...

  2. 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    [源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...

  3. 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    [源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...

  4. 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...

  5. 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合

    背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...

  6. 第11课 std::bind和std::function(2)_std::bind绑定器

    1. 温故知新:std::bind1st和std::bind2nd (1)bind1st.bind2nd首先它们都是函数模板,用于将参数绑定到可调用对象(如函数.仿函数等)的第1个或第2个参数上. ( ...

  7. c++11——std::function和bind绑定器

    c++11中增加了std::function和std::bind,可更加方便的使用标准库,同时也可方便的进行延时求值. 可调用对象 c++中的可调用对象存在以下几类: (1)函数指针 (2)具有ope ...

  8. WPF Bind 绑定

    原文:WPF Bind 绑定 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/74332515 用过W ...

  9. C++11 学习笔记 std::function和bind绑定器

    C++11 学习笔记 std::function和bind绑定器 一.std::function C++中的可调用对象虽然具有比较统一操作形式(除了类成员指针之外,都是后面加括号进行调用),但定义方法 ...

  10. bind绑定服务的生命周期

    bindService(service, conn, flags); * service :意图 * conn :activity和服务的连接通道 * flags : BIND_AUTO_CREATE ...

随机推荐

  1. 玩转iOS开发 - Runloop 具体解释

    Runloop 具体解释

  2. Linux网络编程(3)——多进程、多线程

    在我的里面已经介绍了linux以下c的进程.线程接口,这里就不做过多阐述了. 多进程 这里多进程採用传统的多进程模型.每当有client发来的连接时创建一个进程来处理连接,一个子进程相应一个连接. 有 ...

  3. cocos2d-x 中XML解析与数据存储

    一不小心就玩了一周的游戏了.哎.玩的时候时间过得总是这么快... 于是今天决定看一下之前不怎么非常熟悉的XML;(之前做游戏时数据的储存用到过XML,但这块是还有一个同事在做,所以不怎么熟悉), 看了 ...

  4. HDU5411CRB and Puzzle(矩阵高速幂)

    题目链接:传送门 题意: 一个图有n个顶点.已知邻接矩阵.问点能够反复用长度小于m的路径有多少. 分析: 首先我们知道了邻接矩阵A.那么A^k代表的就是长度为k的路径有多少个. 那么结果就是A^0+A ...

  5. 91.Bower : ENOGIT git is not installed or not in the PATH 解决方法

    转自:https://www.haorooms.com/post/bower_error 今天在用bower安装依赖的时候,出现了Bower : ENOGIT git is not installed ...

  6. [codeforces 1037D] Valid BFS? 解题报告(验证bfs序,思维题)

    题目链接:http://codeforces.com/problemset/problem/1037/D 题目大意: 给出一棵树,询问一个序列是否可能为这棵树从节点1开始遍历的bfs序 题解: 对于每 ...

  7. 移动端video播放时不弹出页面层

    移动端视频在播放时会主动弹出页面,有的浏览器不会.对那些会的浏览器进行处理: 直接加上下面三个属性即可,兼容方面就不说了,微信上是很ok的. <video x5-playsinline=&quo ...

  8. jquery的clone()引发的问题,下拉框点击没有反应

    此段代码是对某块元素的移位:上移.下移.对比修改前后的两段代码: 修改前: //点击移位 function move(obj,posi){ var al=$(obj).parent('li').par ...

  9. fastdfs+nginx的安装部署

    原理图: fastdfs适用场景: fastdfs特别适合海量 中小文件(建议范围:4KB< file_size <500MB)为载体的在线服务. 安装系统介绍: CentOS6.6 安装 ...

  10. 解析浏览器和nodejs环境下console.log()的区别

    写在前面的 在开发调试过程中,我们经常需要调用console.log 方法来打印出当前变量的值,然而,console.log在浏览器环境下 有时会出现一些异常的现象 开撸代码 在浏览器和nodejs环 ...