Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * header1.h
- */
- #ifndef HEADER1_H
- #define HEADER1_H
- // Here we include header2.h
- #include <header2.h>
- class someClass {
- someOtherClass* object;
- };
- #endif
- /**
- * header2.h
- */
- #ifndef HEADER2_H
- #define HEADER2_H
- // Here we include header1.h
- #include <header1.h>
- class someOtherClass {
- someClass* object;
- };
- #endif
- /**
- * At this time there is no circular dependency. The compiler only
- * sees the post-processed source files. Here is the source file before processing:
- */
- /**
- * source.c
- */
- #include <header1.h>
- /**
- * We dont care about the rest of the file. So, source.c just has a single #include line
- * to the preprocessor to include header1.h. When building, we first run source.c in
- * the preprocessor, so source.c is modified by the preprocessor to something like:
- */
- /**
- * source.c
- */
- #define HEADER1_H
- #define HEADER2_H
- class someOtherClass {
- someClass* object;
- };
- class someClass {
- someOtherClass* object;
- };
- #endif
- /**
- * The above is what the compiler sees. But wait! when we get to someOtherClass, the
- * someClass class isnt defined yet. So we reach the "someClass* object" line, we get
- * compiler errors do to an unknown class being used, most commonly "missing ';'" errors
- */
Add Comment
Please, Sign In to add comment