Applying the first-class function in all functions
The first-class function is just a normal class. We can treat the first-class function like any other data type. However, in the language that supports the first-class function, we can do the following tasks without invoking the compiler recursively:
- Passing a function as another function's parameter
- Assigning functions to variables
- Storing functions in collections
- Creating new functions from the existing functions at runtime
Fortunately, C++ can be used to solve the preceding tasks. We will discuss it in depth in the following topics.
Passing a function as another function's parameter
Let's start to pass a function as the function parameter. We will choose one of four functions and invoke the function from its main function. The code will look like this:
/* first_class_1.cpp */ #include <functional> #include <iostream> using namespace std; // Defining a type of function named FuncType // representing a function...