[英]Error: Invalid base class C++
任何人都可以解釋導致此錯誤的原因嗎?
Error: Invalid base class
我有兩個類,其中一個是從第二個派生的:
#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
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
我試圖清理我的項目,但徒勞無功。
如果未將數組的大小指定為類的成員,則定義數組( std::string m_graphics[]
)是無效的。 C ++需要事先知道一個類實例的大小,這就是為什么您不能從它繼承的原因,因為C ++在運行時將不知道該繼承類的成員在內存中的可用位置。
您可以在類定義中固定數組的大小,也可以使用指針在堆上分配它,或者使用vector<string>
代替數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.