#include <iostream>
#include <functional>
using namespace 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
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIDIgdW5yZWxhdGVkIGNsYXNzZXMKY2xhc3MgQQp7CnB1YmxpYzoKICAgIHZvaWQgZnVuYygpIHsgY291dCA8PCAiaW4gQTo6ZnVuY1xuIjsgfQp9OwoKY2xhc3MgQgp7CnB1YmxpYzoKICAgIHZvaWQgZnVuYygpIHsgY291dCA8PCAiaW4gQjo6ZnVuY1xuIjsgfQp9OwoKaW50IG1haW4oKQp7CiAgICBBIGE7CiAgICBCIGI7CgogICAgZnVuY3Rpb248dm9pZCgpPiBmOyAgLy8gYSBnZW5lcmljIGZ1bmN0aW9uIHRoYXQgcmV0dXJucyB2b2lkIGFuZCB0YWtlcyBubyBwYXJhbXMKCiAgICBmID0gYmluZCgmQTo6ZnVuYywgJmEpOwogICAgZigpOyAvLyA8LSBjYWxscyBBOjpmdW5jCgoKICAgIGYgPSBiaW5kKCZCOjpmdW5jLCAmYik7CiAgICBmKCk7IC8vIDwtIGNhbGxzIEI6OmZ1bmMKfQ==