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 ...
随机推荐
- [SCSS] Pure CSS for multiline truncation with ellipsis
1. Pure CSS 2. Responsive 3. No need to recalculate on resize or font’s load event 4. Cross browser
- 英语影视台词---七、THE GREAT GATSBY QUOTES
英语影视台词---七.THE GREAT GATSBY QUOTES 一.总结 一句话总结:了不起的盖茨比 1.“So we beat on, boats against the current, b ...
- Linux就该这么学 20181003(第三章管道符)
参考链接https://www.linuxprobe.com/ 输入输出重定向 标准输入重定向STDIN 文件描述符0 默认键盘输入 标准输出重定向STOUT 文件描述符1 默认输出到屏幕 错误输出重 ...
- @Query Annotation in Spring Data JPA--转
原文地址:http://javabeat.net/spring-data-jpa-query/ In my previous post on Spring Data, I have explained ...
- SqlServer存储过程加密与解密
★ 加密存储过程 ★: IF EXISTS (SELECT name FROM sysobjects WHERE name = 'encrypt_this' AND type = 'P') DRO ...
- 【原创】VSFTP: Login failure: 530 Login incorrect的解决办法
1.修改/etc/vsftpd/ftpusers和/etc/vsftpd/user_list中关于root的行,注释掉即可: 2.关闭SELinux:如果不想关闭的话,可以打开home项的布林值:se ...
- RelativeLayout.addRule()方法
RelativeLayout.addRule()方法 通过LayoutParams的 addRule方法来额外的添加别的规则了,android.widget.RelativeLayout.Layout ...
- php获取当前月份的前(后)几个月
//获取当前月份的前一月 function GetMonth($sign) { //得到系统的年月 $tmp_date=date("Ym"); //切割出年份 $tmp_year= ...
- 优动漫PAINT-超简单灌木教程
超简单灌木教程~零基础神马的都能神还原哦! 优动漫PAINT下载:http://wm.makeding.com/iclk/?zoneid=18597 想要Get到更多有关优动漫的信息包括软件下载,可关 ...
- js 监听ios手机键盘弹起和收起的事件
document.body.addEventListener('focusin', () => { //软键盘弹起事件 console.log("键盘弹起") }) docu ...