How to fix cyclic include of header files?

hello,
i have 2 classes (the character class, and another class) which both depend on each other and i have functions which get each other in the parameters so i require to include the class in the character.h and in the class.h i need the character.h. but i cannot compile because of the cyclic include loop that was created. how can i fix it?

The standard solution is to make sure that headers are properly #if guarded, and then to use forward declarations.

// a.h
#if !defined(a_h)
#define a_h

class B; // forward declaration

class A {
public:
    void doSomethingWithB(B &b);
};

#endif // a_h

// b.h
#if !defined(b_h)
#define b_h

class A; // forward declaration

class B {
public:
  void doSomethingWithA(A &a);
};

#endif // b_h

Note that it is impossible to make both “doSomethingWithA()” and “doSomethingWithB()” be inline defined.

oh thank you very much!