Skip to content

Instantly share code, notes, and snippets.

@go101
Created December 9, 2019 18:36
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 go101/28ecd6ad2425898f2cbf68b7302bd95f to your computer and use it in GitHub Desktop.
Save go101/28ecd6ad2425898f2cbf68b7302bd95f to your computer and use it in GitHub Desktop.
use C++ member functions as callbacks
#include <functional>
#include <iostream>
using namespace std;
class C
{
public:
int foo;
void m()
{
cout << foo << endl;
}
};
void g(std::function<void()> f)
{
f();
}
int main()
{
C c;
c.foo = 123;
g(std::bind(&C::m, &c));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment