#include <iostream>
#include <functional>
usingnamespace std;
// 2 unrelated classes
class A
{
public:
void func() { cout << "in A::func\n"; }
};
class B
{
public:
void func() { cout << "in B::func\n"; }
};
int main()
{
A a;
B b;
function<void()> f; // a generic function that returns void and takes no params
f = bind(&A::func, &a);
f(); // <- calls a.func();
f = bind(&B::func, &b);
f(); // <- calls b.func()
}