{

  #define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__)
#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__)
#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__)
#define CC_CALLBACK_3(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, ##__VA_ARGS__)

}

//一个参数的例子

std::bind(&HelloWorld::menuCloseCallback, this,std::placeholders::_1)

{

bind过程分析及传参控制
过程合法性分析
 设f需要的参数个数为N, bind(f…)中,提供的值的个数为V, 提供的占位符个数为S。对于合法的bind调用,必有 N == V + S. 如果V + S 超出N或者小于N, 编译都会报错。
bind返回值的传参调用
·参数个数
f的调用中提供的参数与占位符数量有关,从程序中可以看出。
·参数顺序
参见程序运行结果,参数顺序与std::placeholders中的顺序一致,因此我们可以用bind来重排参数顺序。
这些只是std::bind的基本用法,对std::bind的引入是C++11的一大亮点,将其与lambda表达式、智能指针、绑定引用参数等知识相结合会明显改变原有的代码编写。std::bind的高级用法还需要更深入学习。
————————————————
版权声明:本文为CSDN博主「___Blue_H」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37653144/article/details/79285221

}

C/C++ C++ 11 std::bind()的更多相关文章

  1. C++11 std::bind std::function 高级使用方法

    从最基础的了解,std::bind和std::function /* * File: main.cpp * Author: Vicky.H * Email: eclipser@163.com */ # ...

  2. C++11之std::function和std::bind

    std::function是可调用对象的包装器,它最重要的功能是实现延时调用: #include "stdafx.h" #include<iostream>// std ...

  3. [C/C++11]_[初级]_[std::bind介绍和使用]

    场景 1.C++11 引入了std::function 对象, 这个对象可以通过std::bind封装所有的函数, 并通过代理调用这个std::function的方式调用这个函数. 比如通过统一的方式 ...

  4. C++ 11 std::function std::bind使用

    cocos new 出新的项目之后,仔细阅读代码,才发现了一句3.0区别于2.0的代码: auto closeItem = MenuItemImage::create( "CloseNorm ...

  5. c++11特性与cocos2d-x 3.0之std::bind与std::function

    昨天同事让帮忙写一小功能,才发现cocos2d-x 3.0 和 cocos2d-x 3.0rc0 差别还是相当大的. 发现Label这一个控件,3.0就比rc0版本多了一个创建函数,更为关键的是3.0 ...

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

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

  7. 转 C++11之std::function和std::bind

    std::function是可调用对象的包装器,它最重要的功能是实现延时调用: #include "stdafx.h" #include<iostream>// std ...

  8. C++11中提供了std::bind

    再来看看std::bind C++11中提供了std::bind.bind()函数的意义就像它的函数名一样,是用来绑定函数调用的某些参数的. bind的思想实际上是一种延迟计算的思想,将可调用对象保存 ...

  9. C++11中std::bind的使用

    std::bind: Each argument may either be bound to a value or be a placeholder: (1).If bound to a value ...

随机推荐

  1. spring-boot整合Dubbo分布式架构案例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 3.2.5 2.项目文件目录 3.Maven Plugin管理 总项目 pom.xml配置代码: &l ...

  2. 早日选择一门自己喜欢的,然后瞄准目标,不达目的誓不罢休。像文章的作者一样成为一名成功的IT人士。

    hawk的奋斗历程. 来自:LinuxForum  :http://www3.linuxforum.net/ 原址:http://www.linuxforum.net/forum/gshowflat. ...

  3. 认识setFactory

    平常设置或者获取一个View时,用的较多的是setContentView或LayoutInflater#inflate,setContentView内部也是通过调用LayoutInflater#inf ...

  4. 课下选作Main dc

    一.中后缀定义: 中缀表达式:我们平时写的数学表达式一般为中缀表达式,如"5+2(3(3-12+1))",直接拿中缀表达式直接让计算机计算表达式的结果并不能做到. 后缀表达式:把中 ...

  5. 2018-2019-2 网络对抗技术 20165206 Exp 8 Web基础

    - 2018-2019-2 网络对抗技术 20165206 Exp 8 Web基础 - 实验任务 (1).Web前端HTML(0.5分) 能正常安装.启停Apache.理解HTML,理解表单,理解GE ...

  6. 转载:Linux下启动和关闭Weblogic(管理服务器+被管服务器)

    转载自:http://www.cnblogs.com/nick-huang/p/3834134.html  感谢! Weblogic的管理服务器和被管服务器的启动.关闭,偶尔会用到,却又不常用,导致需 ...

  7. 将windows下的文件上传到Linux服务器上

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/lx_Frolf/article/deta ...

  8. POJ 1860 Currency Exchange (Bellman-Ford)

    题目链接:POJ 1860 Description Several currency exchange points are working in our city. Let us suppose t ...

  9. selenium和phantomjs,完成豆瓣音乐排行榜的内容爬取

    代码要多敲 注释要清晰 哪怕再简单 #使用selenium和phantomjs,完成豆瓣音乐排行榜的内容爬取 #地址:https://music.douban.com/chart #导入需要的模块 f ...

  10. byte与base64string的相互转化以及加密算法

    //在C#中 //图片到byte[]再到base64string的转换: Bitmap bmp = new Bitmap(filepath); MemoryStream ms = new Memory ...