C++11 Lambda表达式实例2

来源:互联网 发布:手机店铺销售软件 编辑:程序博客网 时间:2024/06/15 19:20
// lambda1.cpp : Defines the entry point for the console application.
//

#include<iostream>
using namespace  std;
int f1(int);
int f2(int x, int(*f)(int));
int main(int argc, char argv[])
{
    //函数指针代入
    int r1 = f2(5, f1);
    cout << r1 << endl;
    //Lambda表达式代入
    int r2 = f2(5, [](int x){return x * 5; });
    cout << r2 << endl;
    cin.get();
}
int f1(int x)
{
    return x * 5;
}
int f2(int x, int(*f)(int))
{
    return x*(*f)(5);

}


0 0