本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
Sorry I have to write the rest in English. The ANCI C++ working paper indicates that "inline" is not required, but should be respected.
If a compiler is implemented correctly, it should handle inline virtual as follows: the function can be inlined if the compiler knows the actual object. However if the method invocation is via a pointer or a reference, then the inline part should be ignored by the compiler since which method to be invoked will be determined at runtime. Some compilers may decide to inline a method invoked via a pointer to an object whose dynamic type is known at compile time, which is fine.
Also some compilers decide where to put the vtbl based on that translation unit where you defined the first (or last or whatever) non-pure,non-inline virtual function, so if you happen to use such a compiler and have declared *all* your virtual function inline, this could be a problem.
Compilers are occasionally implemented incorrectly. I remember on the average one out of six compilers handle smart pointer incorrectly by deleting an extra reference counting due to promotion. As a result three years later (or even longer, or maybe never) the application crashes due to the client code trys to access a non exist object. These kinds of bugs are extreamly to find.
更多精彩文章及讨论，请光临枫下论坛. 网址: rolia.net/zh
This post has been archived. It cannot be replied.