Include Each Other

How can we have two separate files, lets say for example :

"Handler.h"

and

"GameObject.h"

If I want to include GameObject.h in Handler.h and Handler.h in GameObject.h, how in the world are we suppose to do that??

If I try doing it and making an instance of Handler in GameObject class, the compiler barks some annoying errors. Can Someone help me fix
If you think about it, what you're saying doesn't make physical sense, whether we're talking about the real world or the programming world.

How can you have an apple inside of an orange, but then have that orange also inside the same apple?

To avoid circular #including, use a forward declaration of the class you wish to use. If you showed a concrete example, one of us could probably show you how to re-organize the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// Fob.h: ///////////////

class Foobar; // forward declaration

class Fob {
  Foobar* foobar;  
};


/// Foobar.h: ////////////

#include "Fob.h"

class Foobar {
    
};


Last edited on
Topic archived. No new replies allowed.