Error: Invalid C ++ base class

Can someone explain what might cause this error?

Error: Invalid base class 

I have two classes in which one of them is derived from the second:

 #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 

And CGameObject looks like this:

 #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 

I tried to clean my project, but in vain.

+4
source share
1 answer

You cannot define an array ( std::string m_graphics[] ) without specifying its size as a member of the class. C ++ must know the size of the class instance in advance, and that is why you cannot inherit it, since C ++ will not know at run time where the members of the inheriting class will be available in memory.
You can either fix the size of the array in the class definition, or use a pointer and select it on the heap, or use vector<string> instead of the array.

+4
source

Source: https://habr.com/ru/post/1445048/


All Articles