Created
March 8, 2018 11:11
-
-
Save ladislas/e94b3fc126f18c585c8d2f518c9ae113 to your computer and use it in GitHub Desktop.
C++ Function as Parameter
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> | |
// Compile & run with: g++ main.cpp -o main && ./main | |
using namespace std; | |
void caller(std::function<void(string)> func, string arg = "World") { | |
func(arg); | |
} | |
void sayHello(string name) { | |
cout << "Hello, " << name << "!" << endl; | |
} | |
int main() { | |
caller(sayHello, "papa"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment