#include <iostream>
#include <cstdio>
using namespace std;
struct A
{
virtual void func()
{
printf("i: %d\n", i_);
}
void inc()
{
++i_;
}
A()
{
i_=10;
}
private:
int i_;
};
int main()
{
void (A::*p)() = &A::func;
A a;
(a.*p)();
unsigned int vptr_addr = *(unsigned int *)&a;
cout << "vptr_addr:" << hex << vptr_addr << endl;
unsigned int func_addr = *(unsigned int *)vptr_addr;
cout << "func_addr:" << hex << func_addr << endl;
a.inc();
(*(void(*)(A*))(func_addr) )(&a);
A aa;
(*(void(*)(A*))(func_addr) )(&aa);
(*(void(*)(A*))(func_addr) )(&a);
(*(void(*)(A*))(func_addr) )(&aa);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBBCnsKICAgIHZpcnR1YWwgdm9pZCBmdW5jKCkKICAgIHsKICAgICAgcHJpbnRmKCJpOiAlZFxuIiwgaV8pOwogICAgfQogICAgdm9pZCBpbmMoKQogICAgewogICAgICArK2lfOwogICAgfQogICAgQSgpCiAgICB7CiAgICAgIGlfPTEwOwogICAgfQogICAgcHJpdmF0ZToKICAgICAgaW50IGlfOwp9OwoKCmludCBtYWluKCkKewogIHZvaWQgKEE6OipwKSgpID0gJkE6OmZ1bmM7CgogIEEgYTsKICAoYS4qcCkoKTsKCiAgdW5zaWduZWQgaW50IHZwdHJfYWRkciA9ICoodW5zaWduZWQgaW50ICopJmE7CiAgY291dCA8PCAidnB0cl9hZGRyOiIgPDwgaGV4IDw8IHZwdHJfYWRkciA8PCBlbmRsOwoKICB1bnNpZ25lZCBpbnQgZnVuY19hZGRyID0gKih1bnNpZ25lZCBpbnQgKil2cHRyX2FkZHI7CiAgY291dCA8PCAiZnVuY19hZGRyOiIgPDwgaGV4IDw8IGZ1bmNfYWRkciA8PCBlbmRsOwogIGEuaW5jKCk7CiAgKCoodm9pZCgqKShBKikpKGZ1bmNfYWRkcikgKSgmYSk7CgogIEEgYWE7CiAgKCoodm9pZCgqKShBKikpKGZ1bmNfYWRkcikgKSgmYWEpOwoKICAoKih2b2lkKCopKEEqKSkoZnVuY19hZGRyKSApKCZhKTsKCiAgKCoodm9pZCgqKShBKikpKGZ1bmNfYWRkcikgKSgmYWEpOwoKICByZXR1cm4gMDsKfSAgCg==