lamda表达式
#include <iostream>
#include<functional>
using namespace std;
#define debug(x) cout<<#x<<": "<<(x)<<endl;
// 使用函数模板
template<typename T>
int cal(T add, int a, int b) {
return add(a, b);
}
// 使用function,需要添加functional头文件,
// 用法:function<return-type(arg1,...,)>
int cal(function<int(int, int)> add, int a, int b) {
return add(a, b);
}
int main(int argc, char* argv[])
{
auto add = [&](int a, int b)->int {
return a + b;
};
int c = cal(add, 1, 2);
debug(c)
return 0;
}