Whenever I try to make a lot of cpp and header files for a project, I always end up with problems with circular inclusion. I try to use forward declarations, but I still have the problems because I need to access that class's functions, create derived classes, etc. I've tried to find a fix for this, but I can't. Can someone please help me? The header guards don't work (#ifndefine, #define, #endif, and I've tried #pragma once). Nothing seems to work, and I keep getting stuck on this. How do I fix this?
could I just #include in the cpp for using the classes functions and etc and the forward declaration in the header for the pointers and stuff, or would that not work? Also sometimes I get an error with my forward declarations about a redeclaration
That's generally a good strategy, to forward declare in the header and actually #include the relevant headers in the source file.
As for the error with redeclarations, it'd really help if we could see the source code in question, or at the very least be provided more information (such as what the error actually says).
Thank you Albatross, I can't provide the source code right now as all of the programs that I've run into this error have been scrapped due to my (childish) frustration. If this happens again I might dig this thread out of the grave and ask, otherwise, thank you for the help.
That should generally be unnecessary, given that #include is pretty much a copy+paste.
We still don't really know much about what exactly you're trying to do. To make a shot in the complete dark, if your base class needs to maintain a reference to an instance of a derived class, you could forward declare the derived class in the header of the base class.
It might have to do with the ordering in which you've put in your header guards. VS2010 is stupid like that. Personally I've never had to use #pragma once because I do: