Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created December 7, 2011 16:21
Show Gist options
  • Select an option

  • Save pasberth/1443426 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1443426 to your computer and use it in GitHub Desktop.
いめーじをかきとめ
/* イメージを書き留める
* 実際には動きません
*/
void (**func)(); // 関数ポインタへのポインタを用意する
(*func)() // 呼び出し
// funcの値は不変なので、
struct Obj {
void (**func)(); // こんなところに格納しても問題ない
}
void function() {
// 値を実際に作る
}
(*(obj->func)) = function // 値を格納する
(*(obj->func))() // 関数を呼び出す
void overrided_function() {
function()
// オーバーライド
}
(*(obj->func)) = overrided_function // オーバーライドする。
/* obj->func の参照そのものは不変。値を書き換える。
* そうすれば obj->func がどこから参照されようと問題なくオーバーライドできる
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment