std::function用法2

举个例子:

#include <stdio.h>
#include <stdlib.h>
#include <functional>

using FUNC = std::function<int(int, int)>;

int foo(int a, int b)
{
    printf("%d\n", a+b);
    return 0;
}


void play(FUNC f)
{
   f(1,3);
}

typedef int(*func)(int, int);

void show(func f)
{
   f(2,4);
}


int main()
{
   play(foo);
   show(foo);
   return 0;
}

  

输出:4,6

posted @ 2020-02-27 14:34  ren_zhg1992  阅读(110)  评论(0)    收藏  举报