Skip to content

Instantly share code, notes, and snippets.

@ladislas
Created March 8, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ladislas/e94b3fc126f18c585c8d2f518c9ae113 to your computer and use it in GitHub Desktop.
Save ladislas/e94b3fc126f18c585c8d2f518c9ae113 to your computer and use it in GitHub Desktop.
C++ Function as Parameter
#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