码迷,mamicode.com
首页 > 其他好文 > 详细

function复习

时间:2014-09-20 02:14:46      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   div   sp   cti   

#include <iostream>
#include <functional>
using namespace std;

int fun(int a)
{
    std::cout << a <<std::endl;
    return 1;
}

int fun1(std::function<int(int)>* f)
{
    auto fun =    *f; 
    fun(1);
    return 1;
}

int main()
{
    std::function<int(int)> funf;//模板的参数是你要绑定函数的原型
    //第一个参数是要绑定的函数,后面是参数,参数必须要全部写出,后面一个是表示位置信息,表示
    //通过funf调用时传参的位置,_1表示fun1的第一个参数,一般很少不按顺序来,绑定指定的参数最多的是this
    funf = std::bind(fun, placeholders::_1);
    fun1(&funf);
    getchar();
    return 0;
}

 

function复习

标签:style   blog   color   io   os   ar   div   sp   cti   

原文地址:http://www.cnblogs.com/zzyoucan/p/3982776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!