dev- c++ 编译错误 如图如图如图

求大神来帮我找错误,,如图。最后一张是编译时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;
}

2个回答

三个地方有错:

1、

CObject* (__stdcall m_pfnCreateObject)();

这里的意思应该是要声明一个函数指针吧,应该写成:

CObject* (__stdcall  *m_pfnCreateObject)(void);

2、

CObject* CRuntimeClass::CreateObject()
{
    if(m_pfnCreateObject == NULL)
        return NULL;
    return m_pfnCreateObject;
}

这个地方是要返回CObject指针,而不是函数指针,应该改为

CObject* CRuntimeClass::CreateObject()
{
    if(m_pfnCreateObject == NULL)
        return NULL;
    return m_pfnCreateObject();
}

3、

static const CRuntimeClass CObject::classCObject=
{
    "CObject", sizeof(CObject), 0xffff, NULL, NULL, NULL
};

静态常量成员在定义时不能加static,改为

const CRuntimeClass CObject::classCObject=
{
    "CObject", sizeof(CObject), 0xffff, NULL, NULL, NULL
};

能不能上传有行号的代码,还有错误提示清晰点的图片

qq_36760828
qq_36760828 回复lzl569029783: 我把代码贴出来了。大神,帮我看看呗![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/9.gif)
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问