Microsoft Specific
This is a __declspec extended attribute.
This form of __declspec can be applied to any class declaration, but should only be applied to pure interface classes, that is, classes that will never be instantiated on their own. The __declspec stops the compiler from generating code to initialize the vfptr in the constructor(s) and destructor of the class. In many cases, this removes the only references to the vtable that are associated with the class and, thus, the linker will remove it. Using this form of __declspec can result in a significant reduction in code size.
If you attempt to instantiate a class marked with novtable and then access a class member, you will receive an access violation (AV).
Example// novtable.cpp #include <stdio.h> class __declspec(novtable) X { public: virtual void mf(); }; class Y : public X { public: void mf() { printf("In Y\n"); } }; int main() { // X *pX = new X(); // pX->mf(); // AV at runtime Y *pY = new Y(); pY->mf(); } Output
In Y
END Microsoft Specific
-----------------------------------------------------------------
依照AFX_NOVTABLE的声明,对CObject在debug模式,是不起作用的,而在release模式时将移除CObject的vtable,这是release比debug版本的尺寸小的原因之一吧。
本文地址:http://com.8s8s.com/it/it26342.htm