主要演示一下函数指针,匿名函数的概念。
#include <iostream>
using namespace std;
int Add(int x, int y, int z) {
return x + y + z;
}
int Sub(int x, int y, int z) {
return z - x - y;
}
int Operation(int x, int y, int (*function)(int, int, int)) {
int z = x + y;
int result = function(x, y, z);
result *= 10;
return result;
}
int main()
{
cout << "Program Start:\n";
auto Mul = [](int x, int y, int z) {return x * y * z; };
int x = 2, y = 4;
int result1 = Operation(x, y, &Add);
cout << result1 << endl;
int result2 = Operation(x, y, &Sub);
cout << result2 << endl;
int result3 = Operation(x, y, Mul);
cout << result3 << endl;
return 0;
}