求大神来帮我找错误,,如图。最后一张是编译时dev的报错内容
//AFX.h
#ifndef __AFX_H_
#define __AFX_H_
#include <windows.h>
class CObject;
struct CRuntimeClass
{
// Attribute
LPCSTR m_lpszClassName;
int m_nObjectSize;
UINT m_uSchema;
CObject* (__stdcall m_pfnCreateObject)();
CRuntimeClass* m_pBaseClass;
// operator
CObject* CreateObject();
BOOL IsDerivedFrom(const CRuntimeClass* pBaseClass);
// Implements
CRuntimeClass* m_pNextClass;
};
CObject* CRuntimeClass::CreateObject()
{
if(m_pfnCreateObject == NULL)
return NULL;
return m_pfnCreateObject;
}
BOOL CRuntimeClass::IsDerivedFrom(const CRuntimeClass* pBaseClass)
{
const CRuntimeClass* pClassThis = this;
while(pClassThis != NULL)
{
if(pClassThis == pBaseClass)
{
return TRUE;
}
pClassThis = pClassThis->m_pBaseClass;
}
return FALSE;
}
#define RUNTIME_CLASS(class_name)((CRuntimeClass*)&class_name::class##class_name)
class CObject
{
public:
virtual CRuntimeClass* GetRuntimeClass() const;
virtual ~CObject();
public:
BOOL IsKindOf(const CRuntimeClass* pClass) const;
public:
static const CRuntimeClass classCObject;
};
inline CObject::~CObject(){}
static const CRuntimeClass CObject::classCObject=
{
"CObject", sizeof(CObject), 0xffff, NULL, NULL, NULL
};
CRuntimeClass* CObject::GetRuntimeClass() const
{
return RUNTIME_CLASS(CObject);
}
BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
CRuntimeClass* pClassThis = GetRuntimeClass();
return pClassThis->IsDerivedFrom(pClass);
}
#endif
//main.cpp
#include <iostream>
#include "AFX.h"
using namespace std;
class CPerson : public CObject
{
public:
virtual CRuntimeClass* GetRuntimeClass() const
{
return RUNTIME_CLASS(CPerson);
}
static CRuntimeClass classCPerson;
};
CRuntimeClass CPerson::classCPerson=
{
"CPerson"
};
int main()
{
CObject* pMyCObject = new CObject;
if(pMyCObject->IsKindOf(RUNTIME_CLASS(CPerson)))
{
cout << "Is CPerson inherit\n";
delete pMyCObject;
}
else
{
delete pMyCObject;
}
return 0;
}