Skip to content

Instantly share code, notes, and snippets.

@zigo101
Created December 9, 2019 18:36
Show Gist options
  • Save zigo101/28ecd6ad2425898f2cbf68b7302bd95f to your computer and use it in GitHub Desktop.
Save zigo101/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