错误:无效的基类C++

dzi*_*wna 5 c++ oop class derived-class deriving

请问任何人,解释一下可能导致此错误的原因?

Error: Invalid base class
Run Code Online (Sandbox Code Playgroud)

我有两个类,其中一个派生于第二个类:

#if !defined(_CGROUND_H)
#define _CGROUND_H

#include "stdafx.h"
#include "CGameObject.h"


class CGround : public CGameObject // CGameObject is said to be "invalid base class"
{
private:
    bool m_bBlocked;
    bool m_bFluid;
    bool m_bWalkable;

public:
    bool draw();

    CGround();
    CGround(int id, std::string name, std::string description, std::string graphics[], bool bBlocked, bool bFluid, bool bWalkable);
    ~CGround(void);
};

#endif  //_CGROUND_H
Run Code Online (Sandbox Code Playgroud)

而CGameObject看起来像这样:

#if !defined(_CGAMEOBJECT_H)
#define _CGAMEOBJECT_H

#include "stdafx.h"

class CGameObject
{
protected:
    int m_id;
    std::string m_name;
    std::string m_description;
    std::string m_graphics[];

public:
    virtual bool draw();

    CGameObject() {}
    CGameObject(int id, std::string name, std::string description, std::string graphics) {}

    virtual ~CGameObject(void);
};

#endif  //_CGAMEOBJECT_H
Run Code Online (Sandbox Code Playgroud)

我试着清理我的项目但是徒劳无功.

Ben*_*ery 5

定义array(std::string m_graphics[])而不指定其大小作为类的成员是无效的.C++需要事先知道类实例的大小,这就是为什么你不能继承它,因为C++在运行时不会知道继承类的成员在哪里可用.
您可以在类定义中修复数组的大小,也可以使用指针并在堆上分配它或使用vector<string>而不是数组.