Created
December 7, 2011 16:21
-
-
Save pasberth/1443426 to your computer and use it in GitHub Desktop.
いめーじをかきとめ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* イメージを書き留める | |
| * 実際には動きません | |
| */ | |
| 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