一句话:container<ClassType*>就用mem_fun,container<ClassType>就用mem_fun_ref

参考:

http://www.cplusplus.com/reference/functional/mem_fun/

http://www.cplusplus.com/reference/functional/mem_fun_ref/

其实这里的本质可以看这篇随笔:

http://www.cnblogs.com/qrlozte/p/4453786.html

假设我们把这篇随笔的dosomething_five改为:void dosomething_five(MemberFuncType ptr, MyClass* obj)

实现如下:

void dosomething_five(MemberFuncType ptr, MyClass *obj)
{
(obj->*ptr)();
}

假设改为:void dosomething_five(MemberFuncType ptr, MyClass &obj)

实现如下:

void dosomething_five(MemberFuncType ptr, MyClass &obj)
{
MyClass *p_obj = &obj;
(p_obj->*ptr)();
}

这其实就是mem_fun和mem_fun_ref的区别

mem_fun与mem_fun_ref的区别的更多相关文章

  1. STL中mem_fun与mem_fun_ref的区别[转]

    http://www.cnblogs.com/Purple_Xiapei/archive/2012/05/27/2520483.html STL中mem_fun和mem_fun_ref的用法 分类:  ...

  2. 【转】STL中mem_fun和mem_fun_ref的用法及区别

    原文:http://www.cppblog.com/mysileng/archive/2012/12/25/196615.html 引子: 怎么对容器中的所有对象都进行同一个操作?我们可能首先想到的是 ...

  3. C++ mem_fun 和 mem_fun_ref 的用法

    假设我们有以下的一个类: 另外有一个包含 class A 对象的数组: vector<A> vec; 如何对每一个类的对象调用成员函数print. 做法1: 利用下标 for(int i= ...

  4. STL中mem_fun和mem_fun_ref的用法

    例如:假设有如下的代码: class Employee { public: int DoSomething(){} } std::vector<Employee> Emps; 假设我们要调 ...

  5. Effective STL 中文版(大全)

    Effective STL 中文版(大全) 作者:winter 候捷说,对于STL,程序员有三个境界,开始是使用STL,然后是理解STL,最后是补充STL.Effective STL是一本非常好的书, ...

  6. STL中mem_fun, mem_fun_ref用法

    1.引言 先看一个STL中for_each的用法: #include <iostream> #include <vector> #include <algorithm&g ...

  7. C++中的容器类详解

    一.STL容器类 STL(Standard Template Library)的六大组件:容器(containers).迭代器(iterators).空间配置器(allocator).配接器(adap ...

  8. C++ 容器一些细节

    今天学习是看到了讲解C++容器的一些细节用法,故记之!参考:http://www.cnblogs.com/answeryi/archive/2011/12/16/2289811.html: 目录 == ...

  9. C++ 容器及选用总结

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

随机推荐

  1. android:Layout_weight的深刻理解

    最近写Demo,突然发现了Layout_weight这个属性,发现网上有很多关于这个属性的有意思的讨论,可是找了好多资料都没有找到一个能够说的清楚的,于是自己结合网上资料研究了一下,终于迎刃而解,写出 ...

  2. 实现微信小程序的3rd_session

    function 3rd_session($len) { $fp = @fopen('/dev/urandom','rb'); $result = ''; if ($fp !== FALSE) { $ ...

  3. 显示器驱动程序 NVIDIA Windows Kernel Mode Driver Version 已停止响应 并且己成功恢复 解决方法

    原文:http://news.160.com/?p=1890 在玩游戏中 经常 出现显示器驱动程序 NVIDIA Windows Kernel Mode Driver Version 已停止响应 并且 ...

  4. [Compose] 15. Applicative Functors for multiple arguments

    Working our way backwards from solution to problem, we define an applicative functor, then use it to ...

  5. (C++)浅谈多态基类析构函数声明为虚函数

    主要内容: 1.C++类继承中的构造函数和析构函数 2.C++多态性中的静态绑定和动态绑定 3.C++多态性中析构函数声明为虚函数 1.C++类继承中的构造函数和析构函数 在C++的类继承中, 建立对 ...

  6. Discuz常见小问题-如何禁止用户发言,快速删除某个用户的所有帖子

    用户-用户组,勾选批量编辑,然后点击批量编辑的链接   点击论坛相关-帖子相关,然后把指定用户组的允许发新话题设置为否,拉到底部,点击提交   以一个普通用户重新登录,尝试发帖报错,说明已经设置成功 ...

  7. Inside GDALAllRegister之三: 注册指定驱动

    现在来仔细分析如何注册一个驱动的代码,看下面代码: #ifdef FRMT_vrt GDALRegister_VRT(); #endif 编译时指定或者取消FRMT_vrt,可以控制这条语句是否编译到 ...

  8. Oracle中CBO优化器简介

    Oracle中CBO优化器简介 Oracle数据库中的优化器是SQL分析和执行的优化工具.它负责制定SQL的执行计划,也就是它负责保证SQL的执行计划的效率最高,比如优化器决定Oracle以什么样的方 ...

  9. VMWare Workstation 15 serial number

    Serial number:YZ718-4REEQ-08DHQ-JNYQC-ZQRD0 该Key仅供体验,支持正版,从我做起. 点击此处购买正版

  10. Reusing dialogs with a dialog pool--一个sql server service broker例子

    一个sql server service broker例子 ----------------------------------- USE master GO -------------------- ...