In C ++, I have a double problem:
File stuffcollection.h
#pragma once #ifndef STUFFCOLLECTION_H #define STUFFCOLLECTION_H #include "Stage.h" class Stuffcollection { public: bool myfunc( Stage * stage ); }; #endif
Stage.h file:
#pragma once #ifndef STAGE_H #define STAGE_H #include "Stuffcollection.h" class Stage {
Compiler Error:
\Stuffcollection.h|(line were bool myfunc is declared)|error: 'Stage' has not been declared| ||=== Build finished: 1 errors, 0 warnings ===|
Can someone explain why this is happening and how it can be solved? I already use include guard and the pragma after the preprocessor directive, and it just doesn't work.
(If I remove #include "Stuffcollection.h" from stage.h and comment out the corresponding lines that use it in stage.cpp, the rest of my code works fine. It's really simple when the stuffcollection is at the stage that it suddenly stops working. )
PS: stage is just one example, I use stuffcollection in almost every other file, and every time I get this problem.
EDIT : I followed the suggestion, and now the problem is invalid use of incomplete type , i.e. while the answers given to solve the circular dependency problem, they do not solve the problem I'm dealing with, My problem continues to Circular dependencies / Incomplete types .
EDIT : both resolved.
source share