title: C++ #include guards
body: <p>SOLVED</p>
  
  <p>What really helped me was that I could #include headers in the .cpp file with out causing the redefined error.</p>
  
  <hr>
  
  <p>I'm new to C++ but I have some programming experience in C# and Java so I could be missing something basic that's unique to C++.</p>
  
  <p>The problem is that I don't really know what's wrong, I will paste some code to try to explain the issue.</p>
  
  <p>I have three Classes, GameEvents, Physics and GameObject. I have headers for each of them.
  GameEvents has one Physics and a list of GameObjects.
  Physics has a list of GameObjects.</p>
  
  <p>What I'm trying to achieve is that I want GameObject to be able to access or own a Physics object.</p>
  
  <p>If I simply #include "Physics.h" in GameObject I get the
  "error C2111: 'ClassXXX' : 'class' type redifinition" which I understand.
  And this is where I thought #include-guards would help so I added an include guard to my Physics.h since that's the header I want to include twice.</p>
  
  <p>This is how it looks</p>
  
  <pre><code>#ifndef PHYSICS_H
  #define PHYSICS_H
  
  #include "GameObject.h"
  #include &lt;list&gt;
  
  
  class Physics
  {
  private:
      double gravity;
      list&lt;GameObject*&gt; objects;
      list&lt;GameObject*&gt;::iterator i;
  public:
      Physics(void);
      void ApplyPhysics(GameObject*);
      void UpdatePhysics(int);
      bool RectangleIntersect(SDL_Rect, SDL_Rect);
      Vector2X CheckCollisions(Vector2X, GameObject*);
  };
  
  #endif // PHYSICS_H
  </code></pre>
  
  <p>But if I #include "Physics.h" in my GameObject.h now like this:</p>
  
  <pre><code>#include "Texture2D.h"
  #include "Vector2X.h"
  #include &lt;SDL.h&gt;
  #include "Physics.h"
  
  class GameObject
  {
  private:
      SDL_Rect collisionBox;
  public:
      Texture2D texture;
      Vector2X position;
      double gravityForce;
      int weight;
      bool isOnGround;
      GameObject(void);
      GameObject(Texture2D, Vector2X, int);
      void UpdateObject(int);
      void Draw(SDL_Surface*);
      void SetPosition(Vector2X);
      SDL_Rect GetCollisionBox();
  };
  </code></pre>
  
  <p>I get multiple issues that don't understand why they're showing up.
  If I don't #include "Physics.h" my code runs just fine.</p>
  
  <p>I'm very grateful for any help.</p>