When you forward to declare a type, all compilers know that this type exists; he knows nothing about his size, members or methods, so he is called the Incomplete type
You cannot use an incomplete type to declare a member (since compilation must know the size of the type when declaring it), and therefore you get an error.
You do not need to # include "creature.h" in action.h, but you just need to send the Creature class declaration. You need # to include "action.h" in creature.h
Your header files should have the following structure:
creature.h
#include "effect.h" #include "action.h" #include "heedupdate.h"
action.h
class creature;
This uses two rules:
- You can declare functions or methods that accept / return incomplete types:
action.h declares only a function that takes an incomplete type (Creature)
- You cannot declare a member an incomplete type.
creature.h should include action.h as it declares a member of type Action .
source share