您的位置:首页 > 其它

STL的bind1st,bind2nd,mem_fun,mem_fun_ref使用示例

2011-02-09 11:31 579 查看
// STL的bind1st,bind2nd,mem_fun,mem_fun_ref使用示例
// VC2008

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <functional>

int Sub(int x, int y)
{
 return x-y;
}

class Add
{
public:
 int add100(int x)
 {
  return x + 100;
 }
};

int _tmain(int argc, _TCHAR* argv[])
{
 std::cout << "100-200 = " << (std::bind1st(std::ptr_fun(Sub), 100))(200) << std::endl;
 std::cout << "200-100 = " << (std::bind2nd(std::ptr_fun(Sub), 100))(200) << std::endl;

 Add add;
 std::cout << "200+100 = " << (std::mem_fun(&Add::add100))(&add, 200) << std::endl;
 std::cout << "200+100 = " << (std::mem_fun_ref(&Add::add100))(add, 200) << std::endl;
 return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  fun class