- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_function.cpp
More file actions
Latest commit
30 lines (20 loc) · 803 Bytes
/
Copy pathstd_function.cpp
File metadata and controls
30 lines (20 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Function objects are objects specifically designed to be used with a syntax similar to that of functions.
// Instances of std::function can store, copy, and invoke any Callable target -- functions, lambda expressions,
// bind expressions, or other function objects, as well as pointers to member functionsand pointers to data members.
#include<iostream>
#include<functional>
voidFunction(constint& val) {
std::cout << "The value is: " << val << std::endl;
}
voidFunction2(constint& val, constint &val2) {
std::cout << "The values are: " << val << " , " << val2 << std::endl;
}
intmain()
{
int val = 20, val2 = 10;
std::function<void(constint&)> func = Function;
std::function<void(constint&, constint&)> func2 = Function2;
func(val);
func2(val, val2);
std::cin.get();
}