home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16130 < prev    next >
Encoding:
Text File  |  1992-11-11  |  1.6 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!rational.com!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Subject: Re: Multiple Header Files Problem
  5. Message-ID: <rmartin.721531576@thor>
  6. Sender: news@rational.com
  7. Organization: Rational
  8. References: <rmartin.721359424@thor> <1992Nov10.104447.12882@us-es.sel.de> <rmartin.721442494@thor> <1drjpsINN1jr@alnitak.usc.edu>
  9. Date: Thu, 12 Nov 1992 01:26:16 GMT
  10. Lines: 51
  11.  
  12. coller@alnitak.usc.edu (Lee D. Coller) writes:
  13.  
  14. |In article <rmartin.721442494@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  15. |>
  16. |>What I had not realized, until you (and many others) pointed it out to
  17. |>me, is that the #ifndef convention breaks inclusion cycles.  Of course
  18. |>it does.
  19. |>
  20.  
  21. |Actually it doesn't entirely solve the circular dependency problem.
  22. |Consider two files, file a.h containing:
  23.  
  24. |#ifndef a_h
  25. |#define a_h
  26.  
  27. |#include "b.h"
  28.  
  29. |class a {
  30. |public:
  31. |    b* _b;
  32. |    void do_b_fnc() { _b->b_fnc(); }
  33. |    void a_fnc();
  34. |};
  35. |#endif
  36.  
  37. |File b.h contains:
  38.  
  39. |#ifndef b_h
  40. |#define b_h
  41.  
  42. |#include "a.h"
  43.  
  44. |class b {
  45. |public:
  46. |    a* _a;
  47. |    void do_a_fnc() { _a->a_fnc(); }
  48. |    void b_fnc();
  49. |};
  50. |#endif
  51.  
  52. This is an excellent example of the dangers of inline functions.  In
  53. this case, the reason that class a or b cannot be forward declared is
  54. because of the inline functions.  If the inlines are removed, then
  55. both classes could be forward delcared and the cycle could be broken.
  56.  
  57.  
  58. --
  59. Robert Martin                        Training courses offered in:
  60. R. C. M. Consulting                       Object Oriented Analysis
  61. 2080 Cranbrook Rd.                        Object Oriented Design
  62. Green Oaks, Il 60048 (708) 918-1004       C++
  63.