home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18607 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.2 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!wotan.compaq.com!twisto.eng.hou.compaq.com!gocart.eng.hou.compaq.com!giangd
  3. From: giangd@gocart.eng.hou.compaq.com (Giang Dao)
  4. Subject: class forward ref. in C++
  5. Message-ID: <1992Dec31.201340.13142@twisto.eng.hou.compaq.com>
  6. Sender: news@twisto.eng.hou.compaq.com (Netnews Account)
  7. Organization: Compaq Computer Corporation
  8. Date: Thu, 31 Dec 1992 20:13:40 GMT
  9. Lines: 30
  10.  
  11. Dear C++ gurus,
  12. I have the following question :
  13.  
  14. class A
  15.   {
  16.    ...
  17.    B * bptr;
  18.    ...
  19.   }
  20.  
  21. class B
  22.   {
  23.    ...
  24.    A * aptr;
  25.    ...
  26.   }
  27.  
  28. The C++ compiler doesnot allow this since B is not defined
  29. yet in class A definition and B can not be defined first
  30. since A is not defined yet. I can use void * instead and
  31. overcast the type but this is really inconvenient. Worse,
  32.  I have members in A and B that have same names.
  33. This would result in no compilation errors if I typecast the
  34. wrong class. Any work-around without using void * and declare
  35. different member's names in A and B. I use the MS C++ compiler.
  36. Could some body try it on BC++ ? 
  37. Theoretical this should be possible since aptr and bptr are
  38. just address holders and not depending on the structture of
  39. A or B.
  40. Thanks,
  41.