boost::bind应用示例
- // testBind.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <boost/bind.hpp>
- #include <boost/function.hpp>
- #include <assert.h>
- #include <iostream>
- /*
- Title:boost::bind应用示例
- 示例运行环境:
- [1]boost 1.39 SDK
- [2]VisualStudio2008 + SP1
- 示例内容:
- Precondition:MySubClass实例方法 参数方法列表 已知
- Do:控制权从MyParentClass实例方法,转移到,MySubClass实例方法。
- */
- //MyDataType:自定义数据类型
- struct MyDataType{
- MyDataType() {}
- MyDataType(int nV):m_nV(nV) {}
- int m_nV;
- };
- //MyParentClass:框架Class,负责消息派发
- class MyParentClass{
- public:
- boost::function<int(int,MyDataType)> m_fSub;
- int CallSubClassFunc(int nDT,MyDataType mdtDT)
- {
- int nR = m_fSub(nDT,mdtDT);
- return nR;
- }
- };
- //MySubClass:业务逻辑层,负责消息处理
- class MySubClass{
- public:
- int Run(int nDT,MyDataType mdtDT)
- {
- return nDT+mdtDT.m_nV;
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- MyParentClass mpc;
- MySubClass msc;
- //两种实例方法间,建立联系
- mpc.m_fSub=boost::bind<int>(&MySubClass::Run,msc,_1,_2);
- //触发调用
- int nR=mpc.CallSubClassFunc(2,MyDataType(3));
- assert(nR==5);
- return 0;
- }
http://blog.csdn.net/lee353086/article/details/5269910
boost::bind应用示例的更多相关文章
- boost::bind和boost::function使用示例
C++11已支持bind和function,之前的不支持,但可以借助boost达到同样目的.看如下两段代码: 1) 创建HDFS目录 void hdfs::init() { if (0 == hdfs ...
- 使用BOOST BIND库提高C++程序性能
Boost.Bind为函数和函数对象,值语义和指针提供语义了一致的语法.我们首先通过一些简单的例子来看看它的基本用法,之后我们会延伸到嵌套绑定以实现功能组合.理解bind用法的一个关键是理解占位符(p ...
- Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET
Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET Boost::Thread使用示例 分类: C/C++ 2011-07-06 14:48 5926 ...
- boost asio 学习(二)了解boost::bind
2.了解boost::bind使用boost::bind封装一个函数,考虑以下例子示例2a #include <iostream> #include <boost/bind.hpp& ...
- 【转】bind简单示例
bind简单示例代码 namespace { class placeholder_ {}; placeholder_ __1; } template <typename R, typename ...
- boost::bind 详解
使用 boost::bind是标准库函数std::bind1st和std::bind2nd的一种泛化形式.其可以支持函数对象.函数.函数指针.成员函数指针,并且绑定任意参数到某个指定值上或者将输入参数 ...
- 1,Boost -> Bind
#include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <iostream> usin ...
- boost::bind
bind并不是一个单独的类或函数,而是非常庞大的家族,依据绑定的参数个数和要绑定的调用对象类型,总共有十个不同的形式,但它们的名字都叫bind. bind接受的第一个参数必须是一个可调用对象f,包括函 ...
- boost::bind 和 boost::function 基本用法
这是一篇介绍bind和function用法的文章,起因是近来读陈硕的文章,提到用bind和function替代继承,于是就熟悉了下bind和function的用法,都是一些网上都有的知识,记录一下,期 ...
随机推荐
- PDFObject.js、jquerymedia.js、pdf.js的对比
由于在做手机项目中需要用到预览pdf文件的需求,一搜还真多,试用后发现兼容性不是很好,大多需要浏览器对pdf阅读的支持: 如果你只是想不依赖浏览器本身对pdf解析的情况下,在手机展示pdf文件,就需要 ...
- error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).
用Visual Studio2015 编译时,遇到如下编译错误: error C2220: warning treated as error - no 'object' file generated ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Android开发之SpannableString具体解释
在实际的应用开发过程中常常会遇到.在文本的不同部分显示一些不同的字体风格的信息如:文本的字体.大小.颜色.样式.以及超级链接等. 普通情况下,TextView中的文本都是一个样式.对于类似的情况.能够 ...
- html5 在移动端的缩放控制
viewport 语法介绍: 01 <!-- html document --> 02 <meta name="viewport" 03 content= ...
- Tomcat生产中优化JVM的配置实例
root 1208 1 0 11月25 ? 00:15:32 /home/root/jvm/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/ ...
- target属性值
有 4 个保留的目标名称用作特殊的文档重定向操作: _blank 浏览器总在一个新打开.未命名的窗体中加载目标文档. _self 这个目标的值对全部没有指定目标的 <a> 标签是默认目标, ...
- JNDI 的理解
JNDI是 Java 命名与文件夹接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之中的一个,不少专家觉得,没有透彻理解JNDI的意义和作用 ...
- hdu 4059 The Boss on Mars
The Boss on Mars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- ets学习
http://diaocow.iteye.com/blog/1768647 http://www.cnblogs.com/me-sa/archive/2011/08/11/erlang0007.htm ...