Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. /**
  2. * header1.h
  3. */
  4.  
  5. #ifndef HEADER1_H
  6. #define HEADER1_H
  7.  
  8. // Here we include header2.h
  9. #include <header2.h>
  10.  
  11. class someClass {
  12. someOtherClass* object;
  13. };
  14.  
  15. #endif
  16.  
  17. /**
  18. * header2.h
  19. */
  20.  
  21. #ifndef HEADER2_H
  22. #define HEADER2_H
  23.  
  24. // Here we include header1.h
  25. #include <header1.h>
  26.  
  27. class someOtherClass {
  28. someClass* object;
  29. };
  30.  
  31. #endif
  32.  
  33. /**
  34. * At this time there is no circular dependency. The compiler only
  35. * sees the post-processed source files. Here is the source file before processing:
  36. */
  37.  
  38. /**
  39. * source.c
  40. */
  41. #include <header1.h>
  42.  
  43. /**
  44. * We dont care about the rest of the file. So, source.c just has a single #include line
  45. * to the preprocessor to include header1.h. When building, we first run source.c in
  46. * the preprocessor, so source.c is modified by the preprocessor to something like:
  47. */
  48.  
  49. /**
  50. * source.c
  51. */
  52.  
  53. #define HEADER1_H
  54.  
  55. #define HEADER2_H
  56.  
  57. class someOtherClass {
  58. someClass* object;
  59. };
  60.  
  61. class someClass {
  62. someOtherClass* object;
  63. };
  64.  
  65. #endif
  66.  
  67. /**
  68. * The above is what the compiler sees. But wait! when we get to someOtherClass, the
  69. * someClass class isnt defined yet. So we reach the "someClass* object" line, we get
  70. * compiler errors do to an unknown class being used, most commonly "missing ';'" errors
  71. */
Add Comment
Please, Sign In to add comment