标签:异常 ret col nal 实例 包含 表达 目标 其他
#include <iostream>
#include <functional>
auto g_lambda = [](int a, int b) -> int { return a + b; };
int add(int a, int b) {
return a + b;
}
class Add {
public:
int operator () (int a, int b) {
return a + b;
}
};
int main()
{
std::function<int(int, int)> func1 = add;
int result1 = func1(1, 2);
std::cout << "result1: " << result1 << std::endl;
std::function<int(int, int)> func2 = g_lambda;
int result2 = func2(1, 3);
std::cout << "result2: " << result2 << std::endl;
std::function<int(int, int)> func3 = Add();
int result3 = func3(1, 4);
std::cout << "result2: " << result3 << std::endl;
return 0;
}
// 输出结果为:
// result1: 3
// result2: 4
// result2: 5
标签:异常 ret col nal 实例 包含 表达 目标 其他
原文地址:https://www.cnblogs.com/tongyishu/p/13194348.html