C++ メンバ関数のポインタをアドレスとして取得
C++ のメンバ関数は関数ポインタをとる事は出来てもアドレスは無理。とはいえ JIT で必要なので以下の方法でとる事に。
実体は this が第一引数のマングリングされた関数だから呼べるのは当たり前だけど合法かが微妙。
const Object t = Object::makeFixnum(1234); fixedint (Object::*func1)() const = &Object::toFixnum; // メンバ関数ポインタによる呼び出し printf("func1=%d\n", (t.*func1)()); // 無理矢理 void** p = reinterpret_cast<void**>(&func1); fixedint (*func2)(const Object*) = reinterpret_cast<fixedint (*)(const Object*)>(*p); printf("func2=%d address=%p\n", (*func2)(&t), func2);