#ifdef _AFXDLL
class CObject
#else
class AFX_NOVTABLE CObject//问题:AFX_NOVTABLE是怎么回事,起到什么作用?
#endif
{
public:// Object model (types, destruction, allocation)
virtual CRuntimeClass* GetRuntimeClass() const;
virtual ~CObject();  // virtual destructors are necessary // Diagnostic allocations
void* PASCAL operator new(size_t nSize);
void* PASCAL operator new(size_t, void* p);
void PASCAL operator delete(void* p);
#if _MSC_VER >= 1200
void PASCAL operator delete(void* p, void* pPlace);
#endif#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
// for file name/line number tracking using DEBUG_NEW
void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#if _MSC_VER >= 1200
void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
#endif
#endif // Disable the copy constructor and assignment by default so you will get
//   compiler errors instead of unexpected behaviour if you pass objects
//   by value or assign objects.
protected:
CObject();
private:
CObject(const CObject& objectSrc);              // no implementation
void operator=(const CObject& objectSrc);       // no implementation// Attributes
public:
BOOL IsSerializable() const;
BOOL IsKindOf(const CRuntimeClass* pClass) const;// Overridables
virtual void Serialize(CArchive& ar);#if defined(_DEBUG) || defined(_AFXDLL)
// Diagnostic Support
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif// Implementation
public:
static const AFX_DATA CRuntimeClass classCObject;
#ifdef _AFXDLL
static CRuntimeClass* PASCAL _GetBaseClass();
#endif
};

解决方案 »

  1.   

    // This macro is used to reduce size requirements of some classes
    #ifndef AFX_ALWAYS_VTABLE
    #ifndef AFX_NOVTABLE
    #if _MSC_VER >= 1100 && !defined(_DEBUG)
    #define AFX_NOVTABLE __declspec(novtable)
    #else
    #define AFX_NOVTABLE
    #endif
    #endif
    #endif
      

  2.   

    novtableSee Also
    __declspec | C++ Keywords
    Microsoft SpecificThis 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 ed 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