Circular Dependencies / Incomplete Types

后端 未结 3 1090
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 19:19

In C++, I have a problem with circular dependencies / incomplete types. The situation is as follows:

Stuffcollection.h

#include \"Spritesheet.h\";
cl         


        
3条回答
  •  粉色の甜心
    2020-12-11 19:47

    You should include Spritesheet.h in Stuffcollection.cpp
    Just use forward declaration in the header file not the cpp file, that solves the circular dependency of the header file. The source file has no circular dependency actually.

    Stuffcollection.cpp needs to know the complete layout of class Spritesheet(because you dereference it), So you need to include the header which defines the class Spritesheet in that file.

    From your previous Q here, I believe that class Stuffcollection is used in the class declaration of Spritesheet header file and hence the above proposed solution.

提交回复
热议问题