C++ #include guards

后端 未结 8 693
鱼传尺愫
鱼传尺愫 2020-11-22 13:24

SOLVED

What really helped me was that I could #include headers in the .cpp file with out causing the redefined error.


I\'m new to C++ but I have some p

8条回答
  •  名媛妹妹
    2020-11-22 13:49

    You have circular references here: Physics.h includes GameObject.h which includes Physics.h. Your class Physics uses GameObject* (pointer) type so you don't need to include GameObject.h in Physics.h but just use forward declaration - instead of

    #include "GameObject.h" 
    

    put

    class GameObject;   
    

    Furthermore, put guards in each header file.

提交回复
热议问题