STL的bind1st,bind2nd,mem

    技术2024-11-29  32

    // 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;}

    最新回复(0)