Hello,
I'm new here, so I hope I'll ask my question correctly. I have an assignment to create a "text-based cosmic adventure" and all went well until now. My project is separated into several header and implementation files. Problem arises only when I include certain file in another header file. Compiler writes the famous "myClass was not declared in this scope" error. And I really don't know what I'm doing wrong (or better said what to do).
I have a tip, but better first some code:
I think there could be some sort of cycle between Location.h and Planet.h. First Location.h includes MainMenu.h, which then includes Planet.h, that includes again Location.h. But I really don't know how to prevent this, because I need all headers to be included.Code:// Location.h #include "MainMenu.h" class Location {...} // MainMenu.h #include "Planet.h" class MainMenu {...} // Planet.h #include <vector> #include "Location.h" class Planet { ... vector<Location> location; // error: 'Location' was not declared in this scope ... }
Do you think this is the reason or is it something else? Could you please show me a solution to this problem?
Thank you very much
Note: When I do not include MainMenu.h in Location.h, the error in Planet.h doesn't occur. but I'd really like to be able to use MainManu functionality (well, better said, I need to, because it controls the whole game).
P.S.: At the beginning of every file I of course have that thing against cycles:
so there shouldn't be any "inclusion cycle problem".Code:#ifndef LOCATION_H #define LOCATION_H ... #endif