#include <iostream>
using namespace std;
class B {
public:
void up() {
std::cout << "up" << std::endl;
}
void down() {
std::cout << "down" << std::endl;
}
void init( void(B::*someFunc)() , void(B::*otherFunc)() ) {
m_execute = someFunc;
B* newB = new B();
m_b = newB;
m_b->m_execute = otherFunc;
}
void find() {
run_my_execute();
m_b->run_my_execute();
}
private:
void(B::*m_execute)();
B* m_b;
void run_my_execute() {
(this->*m_execute)();
}
};
int main(){
B* b = new B();
b->init(&B::up, &B::down);
b->find();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQiB7CnB1YmxpYzoKICAgIHZvaWQgdXAoKSB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJ1cCIgPDwgc3RkOjplbmRsOwogICAgfQogICAgdm9pZCBkb3duKCkgewogICAgICAgIHN0ZDo6Y291dCA8PCAiZG93biIgPDwgc3RkOjplbmRsOwogICAgfQogICAgdm9pZCBpbml0KCB2b2lkKEI6Oipzb21lRnVuYykoKSAsIHZvaWQoQjo6Km90aGVyRnVuYykoKSApIHsKICAgICAgICBtX2V4ZWN1dGUgPSBzb21lRnVuYzsKICAgICAgICBCKiBuZXdCID0gbmV3IEIoKTsKICAgICAgICBtX2IgPSBuZXdCOwogICAgICAgIG1fYi0+bV9leGVjdXRlID0gb3RoZXJGdW5jOwogICAgfQogICAgdm9pZCBmaW5kKCkgewogICAgICAgIHJ1bl9teV9leGVjdXRlKCk7CiAgICAgICAgbV9iLT5ydW5fbXlfZXhlY3V0ZSgpOwogICAgfQpwcml2YXRlOgogICAgdm9pZChCOjoqbV9leGVjdXRlKSgpOwogICAgQiogbV9iOwogICAgdm9pZCBydW5fbXlfZXhlY3V0ZSgpIHsKICAgICAgICAodGhpcy0+Km1fZXhlY3V0ZSkoKTsKICAgIH0KfTsKCmludCBtYWluKCl7CiAgICBCKiBiID0gbmV3IEIoKTsKICAgIGItPmluaXQoJkI6OnVwLCAmQjo6ZG93bik7CiAgICBiLT5maW5kKCk7CiAgICByZXR1cm4gMDsKfQoK