passing function to another function in c 2b 2b

Solutions on MaxInterview for passing function to another function in c 2b 2b by the best coders in the world

showing results for - "passing function to another function in c 2b 2b"
Annabel
20 Jul 2018
1#include <vector>
2#include <algorithm>
3#include <iostream>
4
5void transform(std::vector<int>::iterator beginIt,
6    std::vector<int>::iterator endIt,
7    std::vector<int>::iterator destinationBeginIt,
8    int func (int)) {
9  while (beginIt != endIt) {
10    *destinationBeginIt = func(*beginIt);
11    beginIt++;
12    destinationBeginIt++;
13  }
14}
15
16int main() {
17  std::vector<int> numbers{1, 2, 3}; // numbers has 3 values: 1, 2, 3
18  std::vector<int> bigNumbers(3); // bigNumbers has 3 values, default
19                                  // initialized: 0, 0, 0
20
21  transform(
22    numbers.begin(),
23    numbers.end(),
24    bigNumbers.begin(),
25    [](int small) {
26      return small * 10;
27    }
28  );
29
30  // Print the values of bigNumbers
31  for (const auto big : bigNumbers) {
32    std::cout << big << std::endl;
33  }
34}
35
Mohamed-Ali
02 Sep 2018
11
22
33
4int func (int)
5int (*func) (int)
6int (&func) (int)
7
queries leading to this page
pass function through another function c 2b 2bhow to pass a function as argument in c 2b 2bpassing function as argument to another function in c 2b 2bc 2b 2b pass a function with some arguments setc 2b 2b how to take in a function as an argumentc 2b 2b pass a function to another functionpass a function as a argument cpphow to pass a function to another function in c 2b 2bpassing function as patameters c 2b 2bcpp passing a function handlepass function as parameter c 2b 2bpass function to function c 2b 2bpass variable from one function to another c 2b 2b cpp pass value from function to another functionc 2b 2b pass function as argumentpassing function as argument c 2b 2bpass a function from another function in c 2b 2bcpp pass function as argumentpass a function through another function in c 2b 2bc 2b 2b function as argumentpassing a function as argument to another function c 2b 2bc 2b 2b pass premade function as argumentfunction inside another function c 2b 2bpass a function to a function cppc 2b 2b passing a function as an argumentpass function parameter c 2b 2bbest way to pass a function as a parameter in c 2b 2bpassing function as argument in c 2b 2bhow to pass functions as arguments in c 2b 2bpassign a function value to other function in c 2b 2bhow to give function as parameter cpppassing variables into a function c 2b 2bpass a function with parameters to another function c 2b 2bc 2b 2b take function as argumenthow to pass in a function into a function in c 2b 2bhow to pass a function as an argument to another function in c 2b 2bpass function as argument c 2b 2bpass value from one function to another function in c 2b 2bpassing function to another function in c 2b 2b