I have three classes, class Actor, class Cell, and class Behavior. Class Actor instantiates a subclass of Behavior (defined in the Behavior header file). Behavior uses methods to analyze vectors of pointers to Actors and vectors of pointers to Cells. Cells have methods that analyze vectors of pointers to Cells, and they contain vectors of pointers to Actors. Oh yes, and in the Actor header file there is an enumerated Heading data type utilized by all classes in some way. (incorporated by declaring an extern enum Heading data type in each file that includes Actor).
I’ve got most of the code, but hit a sticking point when I got an enormous list of errors related to the includes and recursive includes, and have been toiling away at it for hours. I could use some help figuring out what is the best way to arrange these objects so that they work together.
So, to re-iterate:
Actor: Behavior
Behavior: vector of pointers to Cells, vector of pointers to Actors
Cells: vector of pinters to Cells, vector of pointers to Actors
Heading: Enumerated, declared extern in all classes, currently stored in Actor.
Any advice as to how to go about including which header files where? I’ve tried many many permutations of different forward declarations, includes, etc. I honestly don’t know where to go now.
Thank you!
Edit: Updated my class and header files.
Actor: Move, Heading
Move: Behavior Heading
Behavior: Cell, Actor Heading
Cell: Cell, Actor Heading
Heading: Used by all.
As it stands, here are whats being included:
Behavior.h: Forward declarations of Cell and Actor
Behavior.cpp: Includes Behavior.h, Cell.h, Actor.h
Cell.h: Forward Declaration of Actor
Cell.cpp: includes Cell.h, Heading.h, Actor.h
Actor.h: Includes Behavior.h, Heading.h.
Actor.cpp: includes actor.h
Move.h: Includes Behavior.h, Heading.h
Move.cpp: Includes move.h, Heading.h, Cell.h, Actor.h
Heading: Includes nothing, declares nothing.
Pretty much the only include-related error I’m seeing is the one instantiation of Move in the Actor.h file has an incomplete type.
Edit #2: Added includes for Behavior and Move in actor.cpp and removed them from actor.h, and turned my instantiation to the creation of a pointer, and it coughed and growled at me, but it built successfully. Thanks for your help guys!
As long as the only dependency is a pointer, just use a forward decl. With that rule only include is for actor.h to include behavior.h and heading.h
behavior.h -> declare Cells and Actors
Cells.h -> declare actors
Behavior and cells cpp will have to include the header files of the forward declared classes.
behavior.cpp -> include Cells.h and Actors.h
Cells.cpp -> include actors.h