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的用法,都是一些网上都有的知识,记录一下,期 ...
随机推荐
- Swift 语言概览 -自己在Xcode6 动手写2-tableView
import UIKit class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource { va ...
- Mariadb配置文件优化参数(仅供参考)
[client]#password= your_passwordport= 3306 socket= /tmp/mysql.sock!includedir /opt/local/mys ...
- ios开发缓存处理类NSCash类的了解与使用
一:NSCash的基本了解 #import "ViewController.h" @interface ViewController ()<NSCacheDelegate&g ...
- 【Lucene4.8教程之二】索引 2014-06-16 11:30 3845人阅读 评论(0) 收藏
一.基础内容 0.官方文档说明 (1)org.apache.lucene.index provides two primary classes: IndexWriter, which creates ...
- 并发队列ConcurrentLinkedQueue 和 阻塞队列LinkedBlockingQueue用法
在Java多线程应用中,队列的使用率很高,多数生产消费模型的首选数据结构就是队列(先进先出).Java提供的线程安全的Queue可以分为阻塞队列和非阻塞队列,其中阻塞队列的典型例子是BlockingQ ...
- ArcGIS Runtime支持的GP工具列表(转 )
转自原文 ArcGIS Runtime支持的GP工具列表(转 ) 目前ArcGIS Runtime有两个版本 Basic 版本和Standard版本,而Basic版本不支持Geoprocessing( ...
- LSH︱python实现局部敏感随机投影森林——LSHForest/sklearn(一)
关于局部敏感哈希算法.之前用R语言实现过,可是由于在R中效能太低.于是放弃用LSH来做类似性检索.学了python发现非常多模块都能实现,并且通过随机投影森林让查询数据更快.觉得能够试试大规模应用在数 ...
- p2p网贷系统的架构设计
p2p网贷系统,标准版已经初步完成了. 最近写点总结,也算是分享吧. 简介:p2p网贷系统,是理财类的互联网金融系统.核心功能,就是理财人用户注册,冲钱,然后投标,标到期之后,收到回款.如果不想 ...
- 通过select下拉框里的value控制div显示与隐藏
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 《学习opencv》笔记——关于一些画图的函数
画图函数 (1)直线cvLine函数 其结构 void cvLine(//画直线 CvArr* array,//画布图像 CvPoint pt1,//起始点 CvPoint pt2,//终点 CvSc ...