4.bind绑定
#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绑定的更多相关文章
- jquery中bind()绑定多个事件
bind()绑定事件 $(selector).bind(event,data,function): 参数event为事件名称(如"click,mouseover....."),da ...
- 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
[源码下载] 背水一战 Windows 10 (22) - 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合 作 ...
- 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
[源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...
- 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
背水一战 Windows 10 之 绑定 x:Bind 绑定 x:Bind 绑定之 x:Phase 使用绑定过程中的一些技巧 示例1.演示 x:Bind 绑定的相关知识点Bind/BindDemo.x ...
- 绑定: 通过 Binding 绑定对象, 通过 x:Bind 绑定对象, 通过 Binding 绑定集合, 通过 x:Bind 绑定集合
背水一战 Windows 10 之 绑定 通过 Binding 绑定对象 通过 x:Bind 绑定对象 通过 Binding 绑定集合 通过 x:Bind 绑定集合 示例1.演示如何通过 Bindin ...
- 第11课 std::bind和std::function(2)_std::bind绑定器
1. 温故知新:std::bind1st和std::bind2nd (1)bind1st.bind2nd首先它们都是函数模板,用于将参数绑定到可调用对象(如函数.仿函数等)的第1个或第2个参数上. ( ...
- c++11——std::function和bind绑定器
c++11中增加了std::function和std::bind,可更加方便的使用标准库,同时也可方便的进行延时求值. 可调用对象 c++中的可调用对象存在以下几类: (1)函数指针 (2)具有ope ...
- WPF Bind 绑定
原文:WPF Bind 绑定 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/koloumi/article/details/74332515 用过W ...
- C++11 学习笔记 std::function和bind绑定器
C++11 学习笔记 std::function和bind绑定器 一.std::function C++中的可调用对象虽然具有比较统一操作形式(除了类成员指针之外,都是后面加括号进行调用),但定义方法 ...
- bind绑定服务的生命周期
bindService(service, conn, flags); * service :意图 * conn :activity和服务的连接通道 * flags : BIND_AUTO_CREATE ...
随机推荐
- android:px,dp(dip),sp的差别
1.px:表示屏幕的实际像素,比如320*480的屏幕在横向有320个像素,在纵向有480个像素,假设指定的某个空间的单位为px.那么在不同分辨率下的手机上.显示的都是指定的大小.一般不推荐使用px. ...
- ACM-ICPC Dhaka Regional 2012 题解
B: Uva: 12582 - Wedding of Sultan 给定一个字符串(仅由大写字母构成)一个字母表示一个地点,经过这个点或离开这个点都输出这个地点的字母) 问: 每一个地点经过的次数(维 ...
- 初识BeeFramework
由于近期的项目须要,Hybrid开发成为我開始学习的新知识.非常早之前就了解到两个开发框架--BeeFramework 和 Samurai,可是由于本人一直没有闲暇去研究,所以就一直搁置一旁了.近期才 ...
- 我是怎么从项目中的lib加JAR更换为maven管理的
原来我对maven的使用应该还是去年的时候吧,当时对maven并不感冒(请不要吐槽哈),认为为什么一定要用maven来管理呢,我自己管理jar不是一样么,当时还认为自己管理jar还各种方便还对mave ...
- hdu1281 棋盘游戏 --- 最大匹配
给一个矩形棋盘,上面有一些空格点,能够放象棋中的"车", 现给出空格的坐标,求最多能够放多少个"车"使他们互不攻击(依据象棋规则,每行每列至多仅仅能放一个), ...
- pat(A) 1066. Root of AVL Tree
代码: #include<iostream> #include<cstdio> #include<cmath> #include<stdlib.h> # ...
- 站点搭建从零開始(二)server空间
前面介绍了域名相关知识.这里介绍server,也经常被叫做空间.也就是站点数据实际保存的地方. 1.整体介绍 依据国家相关规定,国内server空间须要进行备案.也就是到相关的机构进行登记.详细方法能 ...
- 在Visual Studio Code中使用C#以及.net core
Working with C# Using .NET Core in Visual Studio Code Note: VS Code does not support debugging appli ...
- m_Orchestrate learning system---二、如何实现验证码自动点击刷新
m_Orchestrate learning system---二.如何实现验证码自动点击刷新 一.总结 一句话总结:传过去的url带随机数来避免读取缓存 onclick="this.src ...
- servlet中怎么注入service
在工作中使用到spring的mvc框架,分为controller/service/dao三个层次.偶尔会用到servlet替换掉controller,这就遇到如何在servlet中使用注入到sprin ...