Created
April 3, 2020 22:12
-
-
Save asa55/521e26d8ef5d13b130a0e28896d970fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
void Print(int s) | |
{ | |
std::cout << s << std::endl; | |
} | |
void ForEach(const std::vector<int>& values, void(*func)(int)) | |
{ | |
for(int value : values) // this is called a range-based for loop, and I love it! // https://www.cprogramming.com/c++11/c++11-ranged-for-loop.html | |
func(value); | |
} | |
int main() | |
{ | |
std::vector<int> values = { 1, 2, 3, 4, 5, 6, 7, 8 }; | |
auto myfun = Print; | |
ForEach(values, myfun); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment