how to pass function as a parameter in c 2b 2b

Solutions on MaxInterview for how to pass function as a parameter in c 2b 2b by the best coders in the world

showing results for - "how to pass function as a parameter in c 2b 2b"
Kyle
12 Apr 2018
1#include <bits/stdc++.h> 
2using namespace std;
3
4int add(int x, int y){return x+y;}
5int sub(int x, int y){return x-y;}
6int operation (int x, int y,int (*function)(int,int)){return function(x,y);}
7int operation2(int x, int y,std::function<int(int, int)> function){return function(x,y);}
8
9int main()
10{
11    std::cout <<"Values 1 & 3. Pointer function: Add:"<<operation (1,3,&add)<<" Sub:"<<operation (1,3,&sub) << std::endl;
12    std::cout <<"Values 1 & 3. std::function   : Add:"<<operation2(1,3,&add)<<" Sub:"<<operation2(1,3,&sub) << std::endl;
13}
queries leading to this page
how to pass argument to c 2b 2b functionhow to function in a functions parameters in c 2b 2bpassing function to parameter c 2b 2bwhat is a parameter in a function c 2b 2bfunction as a parameter c 2b 2bcreate function inside parameter c 2b 2bhow to pass method as parameter in cppc 2b 2b function parametertake function as argument c 2b 2bpass function parameter c 2b 2bhow to pass a function into a function c 2b 2bc 2b 2b passing function and arguments to other functionc 2b 2b pass in function as argumenthow to reference a function parameter to a value in c 2b 2bhow to pass function as parameter in c 2b 2bc 2b 2b pass function with any argumentscpp pass function as argumenthow to put a function as the parameter of a function in c 2b 2bparameter as function cpppass function as function argument c 2b 2bcan you pass functions as parameters in c 2bc 2b 2b pass parameter to functionfunction with parameter in c 2b 2bc 2b 2b script as parameter to functionc 2b 2b function as parameterfunction as argument c 2b 2bfunction parameter in c 2b 2b how to pass function in c 2b 2bc 2b 2b pass function as argumentreceive function as parameter c 2b 2bsend function as parameter cppc 2b 2b pass a function as an argumentfunction parameter c 2b 2bpassing arguments in c 2b 2b functionspassing parameter to function c 2b 2bgive function type as parameter in cppfunction passing parameter in c 2b 2bc 2b 2b function as argumentfunction in function parameter c 2b 2bhow to pass function as a parameter in c 2b 2bhow to pass a function as a parameter in c 2b 2bwhat is a function argument in c 2b 2bwhy do we pass parameters and argument in functions in c 2b 2bhow to pass a set aa parameter in c 2b 2b functionfunction parameters in c 2b 2bc 2b 2b pass a function as a parameter and call itc 2b 2b function parameter passingc 2b 2b pass function as parameterc 2b 2b pass a function as parametercreate function with parameters in c 2b 2bc 2b 2b passing arguments to a functionpass a function as a param in c 2b 2bpassing function as argument c 2b 2bpassing parameters in c 2b 2b functionspassing 26 parameter to function c 2b 2bc 2b 2b functions with passing parametersfunction as parameter c 2b 2bhow to take a function as an argument c 2b 2bpass function as argument c 2b 2bpass function as parameter c 2b 2bc 2b 2b pass any function as argumentpass argument in function c 2b 2bpass function as argument in c 2b 2bhow to write a function that takes a function as a parameter in c 2b 2bhow to declare function with function as parameter in c 2b 2bc 2b 2b program passing values to function in parameterc 2b 2b how to pass a function as an argumentpass function name through params in c 2b 2bpassing parameters c 2b 2bpassing arguments to a function in cppset argument as a function in c 2b 2bhow to pass function as a parameter in c 2b 2b