C++ 11 bind

#include <iostream>
#include <functional>

using namespace std;

int add(int a, int b) {
    return a + b;
}

int main() {
    
    function<int (int, int)> f = add;
    
    cout<<f(100, 100)<<endl;
    
    function<int (int)> fsingle = bind(add, 123, placeholders::_1);
    
    cout<<fsingle(111)<<endl;
    
    return 0;
}

跟javascript,python这类动态语言接近了

posted @ 2014-12-23 10:41  卖程序的小歪  阅读(123)  评论(0编辑  收藏  举报