#include <iostream>
#include <functional>
class ClassXY
{
using MyFnc = std::function<void()>;
MyFnc function;
public:
ClassXY(MyFnc f)
: function(std::move(f))
{}
void call()
{
function(); // Calls the function
}
};
class Handler
{
public:
void HandleButtonEvent()
{
std::cout << "Handler::HandleButtonEvent2\n";
}
};
int main()
{
// Handler* handler = new Handler;
auto handler = std::make_unique<Handler>()
ClassXY xy(std::bind(&Handler::HandleButtonEvent, handler));
xy.call();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCmNsYXNzIENsYXNzWFkKewoJdXNpbmcgTXlGbmMgPSBzdGQ6OmZ1bmN0aW9uPHZvaWQoKT47CiAgICBNeUZuYyBmdW5jdGlvbjsKCnB1YmxpYzoKICAgIENsYXNzWFkoTXlGbmMgZikKICAgICAgICA6IGZ1bmN0aW9uKHN0ZDo6bW92ZShmKSkKICAgIHt9CgogICAgdm9pZCBjYWxsKCkKICAgIHsKICAgICAgICBmdW5jdGlvbigpOyAgLy8gQ2FsbHMgdGhlIGZ1bmN0aW9uCiAgICB9Cn07CgpjbGFzcyBIYW5kbGVyCnsKcHVibGljOgogICAgdm9pZCBIYW5kbGVCdXR0b25FdmVudCgpCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJIYW5kbGVyOjpIYW5kbGVCdXR0b25FdmVudDJcbiI7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIC8vIEhhbmRsZXIqIGhhbmRsZXIgPSBuZXcgSGFuZGxlcjsKICAgIGF1dG8gaGFuZGxlciA9IHN0ZDo6bWFrZV91bmlxdWU8SGFuZGxlcj4oKQoKICAgIENsYXNzWFkgeHkoc3RkOjpiaW5kKCZIYW5kbGVyOjpIYW5kbGVCdXR0b25FdmVudCwgaGFuZGxlcikpOwoKICAgIHh5LmNhbGwoKTsKfQo=