   Having an issue with back and forth inheritance
  In a 2d game, Im running into a compile error as these two classes include each other, therefore depending on each other to be compiled as well.I have a parent class called Polygon. It has things like x, y, sizex, sizey and all the functions to support those attributes. I created a new class called BoundingRectangle. It's for collision detection, and has things like Intercepts() and IsOnTop(). It uses a Polygon as a parent class. Now, the Polygon also has a function now called GetBounds() and returns a reference of BoundingRectangle. The idea is that my player class, various other sprites and surfaces can inherit this function from the Polygon class. I am wondering if perhaps I need to make a shape class that Bounding Rectangle and Polygon inherit from, or if I should implement a workaround/hack to get it to compile in its current setup.Here's the code of the classes I mentioned:BoundingRectangle.hpp:#ifndef BOUNDING_RECTANGLE_H#define BOUNDING_RECTANGLE_H#include "stdafx.h"#include "Polygon.hpp"class Polygon;class BoundingRectangle : public Polygon{BoundingRectangle(float x, float y, float sizeX, float sizeY): Polygon(x, y, sizeX, sizeY){}bool Intersects(Polygon& poly);bool IsOnTop(Polygon& surfaceBelow);};#endifPolygon.hpp:#ifndef POLYGON_H#define POLYGON_H#include "stdafx.h"#include "BoundingRectangle.hpp"class BoundingRectangle;class Polygon{public:Polygon(float x, float y, float sizeX, float sizeY):x(x), y(y), sizeX(sizeX), sizeY(sizeY){}float GetX();float GetY();void SetX(float x);void SetY(float y);void IncrementX(float x);void IncrementY(float y);void DeincrementX(float x);void DeincrementY(float y);float GetSizeX();float GetSizeY();BoundingRectangle& GetBounds();float GetRightX();float GetBottomY();protected:float x;float y;float sizeX;float sizeY;};#endifPlayer.hpp:#ifndef PLAYER_H#define PLAYER_H#include "stdafx.h"#include "Polygon.hpp"class Player : public Polygon{public:Player(float x, float y, float sizeX, float sizeY): Polygon(x, y, sizeX, sizeY){}private:};#endif
  What is the error you're getting? I'm guessing it has to do with:class Polygon;class BoundingRectangle;these two lines as the compiler probably thinks you're declaring each class in 2 different places.That was the only thing that jumped out in my brief look at your code.   ;  I actually put those in, in attempt to fix the compile errors. The errors are along the lines of undefined classes, cannot find the functions, etc. I know it's because one is trying to compile, and it checks for the compiled version of the other, but that cant be compiled either cause it needs the compiled version of the one I was originally compiling. Doing a class declaration can sometimes help, but I think because of how im using them, it's not the solution in this case. When I get home, ill post some of the errors if it helps.   ;  Thats a problem with you cyclic including headers.Try removing #include "BoundingRectangle.hpp" from your Polygon.hpp file. and only include it in Polygon.cpp.   ;  That would do it, thank you. I couldnt remember the exact way to fix that, was more or less wondering if I needed to do some refactoring.   