Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I set up my includes layout for my program?
    primarykey
    data
    text
    <p>I'm currently trying to make a RPG game and I'm running into some trouble. This is the layout I have so far.</p> <p>Classes:</p> <ul> <li>Actor - Base class for anything that 'exists' such as units, projectiles, etc.</li> <li>Unit - Inherits Actor, basis for all units.</li> <li>Game - It will only have a single instance, and it'll contains pointers to all objects in the game. I plan to make it call a virtual function gameTick on all actors every 0.1 seconds.</li> </ul> <p>The problem I'm having is that I'd like all Actors to have a pointer to the Game instance. If I wanted to have a spell that does 500 radius area damage, I'd like Game to find and return all Unit pointers within that range.</p> <p>My problem is if I include Game in Actor's header file my program won't compile. How can I have my actors have access to Game? Or am I going about this the wrong way?</p> <p>Thanks in advance.</p> <pre><code>// START main.cpp #include &lt;iostream&gt; #include "game.h" int main() { std::cout &lt;&lt; "All done\n"; return 0; } // END main.cpp // START actor.h #ifndef __ACTOR_H_ #define __ACTOR_H_ #include &lt;iostream&gt; //#include "game.h" Causes many errors if uncommented class Actor { public: Actor(); std::string name_; }; #endif // END actor.h // START actor.cpp #include "actor.h" Actor::Actor() { name_ = "Actor class"; } // END actor.cpp // START unit.h #ifndef __UNIT_H_ #define __UNIT_H_ #include "actor.h" class Unit : public Actor { public: Unit(); }; #endif // END unit.h // START unit.cpp #include "unit.h" Unit::Unit() { name_ = "Unit class"; } // END unit.cpp // START game.h #ifndef __GAME_H_ #define __GAME_H_ #include &lt;vector&gt; #include "unit.h" class Game { public: std::vector&lt; Actor * &gt; actors_; std::vector&lt; Unit * &gt; units_; }; #endif // END game.h </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload