I have three classes:
BaseClass
, that contains ElementClass
as field
ElementClass
, that contains BaseClass
as field and ChildClass
as return type (pointer)
ChildClass
, that's inherits from BaseClass
.
When I'm trying to compile this, I am getting
expected class-name before '{' token
for ChildClass
, that was included in ElementClass
, that was included in BaseClass
.
I understand, why is this happens. Because I'm trying to inherit child class from nonexistent, for compiler, class BaseClass
.
I can't understand hot to fix this. Thank you.
Here is code example with this problem
BaseClass.h
#ifndef INHERITTEST_BASECLASS_H
#define INHERITTEST_BASECLASS_H
#include "ElementClass.h"
class ElementClass;
class BaseClass
{
private:
ElementClass *m_someField;
};
#endif
ElementClass.h
#ifndef INHERITTEST_ELEMENTCLASS_H
#define INHERITTEST_ELEMENTCLASS_H
#include "ChildClass.h"
class ChildClass;
class ElementClass
{
private:
ChildClass *m_class;
};
#endif
ChildClass.h
#ifndef INHERITTEST_CHILDCLASS_H
#define INHERITTEST_CHILDCLASS_H
#include "BaseClass.h"
class ChildClass : public BaseClass
{
};
#endif