Created
February 14, 2014 01:37
-
-
Save kkdai/8994287 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
| class AA | |
| { | |
| public: | |
| AA() | |
| { | |
| printf("1"); | |
| } | |
| virtual void F1() | |
| { | |
| printf("2"); | |
| } | |
| void F2() | |
| { | |
| printf("3"); | |
| } | |
| ~AA() | |
| { | |
| printf("4"); | |
| } | |
| } | |
| class BB : public AA //BB繼承AA | |
| { | |
| public: | |
| BB() | |
| { | |
| printf("5"); | |
| } | |
| virtual void F1() | |
| { | |
| printf("6"); | |
| } | |
| void F2() | |
| { | |
| printf("7"); | |
| } | |
| ~BB() | |
| { | |
| printf("8"); | |
| } | |
| } | |
| void main() | |
| { | |
| AA v1; // 1 | |
| v1.F1(); // 2 | |
| v1.F2(); // 3 | |
| BB v2; // 4 | |
| v2.F1(); // 5 | |
| v2.F2(); // 6 | |
| AA *v3 = new BB(); // 7 | |
| v3->F1(); // 8 | |
| v3->F2(); // 9 | |
| delete v3; // 10 | |
| BB *v4; // 11 | |
| v4->F1(); // 12 | |
| v4->F2(); // 13 | |
| BB *v5 = new BB(); // 14 | |
| v5->F1(); // 15 | |
| v5->F2(); // 16 | |
| delete v5; // 17 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
然後以下是我的答案
1: 1 11: (沒東西)
2: 2 12: (應該會有 segment fault)
3: 3 13: 7
4: 1 5 14: 1 5
5: 6 15: 6
6: 7 16: 7
7: 1 5 17: 8 4
8: 6 main結束前: 8 4 4
9: 3
10: 4
然後你的疑問可能有