不知不觉跟随者侯捷的脚步对着电子书看了将近600页,就一个感觉:云里雾里。函数调用一层嵌一层,还有那该死的virtual关键字,每次调用时都得长个心眼,先要看看派生类有没有重写它。吐槽归吐槽,MFC设计之精巧不容质疑,其中的RTTI(Running Time Type Information),动态生成(Dynamic Create),序列化(Serialization),消息映射(Message Map),命令路由(Command Route)(最后这两个还没深入研究),我已经无法用更好的赞美之词去评价它了,至少,在了解它之前我从没见过类似的设计。
好了,下面是我发现的问题以及解释。
电子书第602页(也应该是书本的第537页,我只有电子书,所以这是电子书上显示的页码)上标题为“在CObList中加入CStroke以外的类别”这一小节,侯捷用三个类做写文件的测试,分别是CStroke,CRectangle,CCircule。生成的文件内容如下:
000000: 06 00 FF FF 01 00 07 00 43 53 74 72 6F 6B 65 02 ........CStroke.
000010: 00 02 00 6E 00 00 00 24 00 00 00 6E 00 00 00 24 ...n...$...n...$
000020: 00 00 00 FF FF 01 00 0A 00 43 52 65 63 74 61 6E .........CRectan
000030: 67 6C 65 11 00 00 00 22 00 00 00 33 00 00 00 44 gle...."...3...D
000040: 00 00 00 FF FF 01 00 07 00 43 43 69 72 63 6C 65 .........CCircle
000050: 55 00 00 00 66 00 00 00 77 00 00 00 01 80 02 00 U...f...w.......
000060: 02 00 6E 00 00 00 55 00 00 00 6E 00 00 00 55 00 ..n...U...n...U.
000070: 00 00 03 80 11 00 00 00 22 00 00 00 33 00 00 00 ........"...3...
000080: 44 00 00 00 05 80 55 00 00 00 66 00 00 00 77 00 D.....U...f...w.
000090: 00 00