- 论坛徽章:
- 0
|
回复 50# starwing83
我果然还是没有把我的重点讲明白啊……我太失败了……
这就好像是:- #include <stdio.h>
- class StandardCompiler {
- public:
- virtual int getSomething() = 0;
- };
- class MyCompiler : public StandardCompiler {
- public:
- virtual int getSomething() { return 20; }
- };
- class YourCompiler : public StandardCompiler {
- public:
- virtual int getSomething() { return 47; }
- };
- int main()
- {
- StandardCompiler *c = new MyCompiler;
- printf("%d\n", c->getSomething());
- delete c;
- }
复制代码 62. 原作者说:StandardCompiler 的 getSomething 返回的应该是 47 吧?我手推的!不保证正确哦……
63. 某 PM 说:不带这样简化的。
64. 原作者说:哦我错了,我基础不好。刚才我编译了一下,在我这里输出的是 20。
65. 原作者说:那我来解释下为什么我这里输出了 20:因为 MyCompiler::getSomething 里明确写着 return 20,所以这段程序输出 20。
然后却有很多人跑出来针对 65 大谈「StandardCompiler::getSomething 不一定返回 20,是未定义的,任何解释都是荒诞可笑的」这种和问题完全无关的真理。重点在于人家 65 不是在试图解释 StandardCompiler::getSomething 而是在试图解释 MyCompiler::getSomething 啊 = =
|
|