home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7818 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  67 lines

  1. Path: news.NetVision.net.il!news
  2. From: Ivan Krivyakov <ivan@cmt.co.il>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to prototype a class?
  5. Date: 19 Feb 1996 12:53:15 GMT
  6. Organization: CMT Medical Technologies, ltd.
  7. Message-ID: <4g9rrr$78s@news.NetVision.net.il>
  8. References: <4fvjhe$c6o@nuntius.u-net.net> <DMtxzu.8HK@tr.unisys.com>
  9. NNTP-Posting-Host: cmt13.cmt.co.il
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. "Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com> wrote:
  16.  
  17. > Use a forward declaration:
  18. > class A;      //I promise to define A later.
  19. >
  20. > class B
  21. > {
  22. >  ...
  23. > private:
  24. >     A dataMember; // <--- here is an error!
  25. > };
  26. >
  27. > Class A
  28. > {
  29. >  ...
  30. > private:
  31. >    B dataMember;
  32. > };
  33. >
  34. > Hope this helps.
  35. >
  36. > Benjamin M. Romer
  37.  
  38. Sorry, but this won't work!
  39.  
  40. In the point where you declare B::dataMember, class A is not still defined
  41. although compiler knowns that it exists.
  42.  
  43. To process a declaration of B::dataMember compiler should know, for example, 
  44. what is the size of objects of type A. This is obviously not known for one-pass compiler
  45. in the point where B::dataMember is declared.
  46.  
  47. You may use pointer to A instead of A as follows:
  48.  
  49. class A;
  50.  
  51. class B
  52. {
  53.   ...
  54.   A* dataMember; //<--- legal
  55.   ...
  56. };
  57.  
  58. > #include <stddisclaim.h>
  59.  
  60. Good idea! :)
  61.  
  62. Best regards,
  63. Ivan (ivan@cmt.co.il)
  64.  
  65.  
  66.