home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11732 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  1.9 KB

  1. Xref: sparky comp.lang.c++:11732 comp.std.c++:989
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!ftpbox!motsrd!news
  4. From: shang@corp.mot.com (David (Lujun) Shang)
  5. Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
  6. Message-ID: <1992Jul29.162440.21848@cadsun.corp.mot.com>
  7. Sender: news@cadsun.corp.mot.com
  8. Reply-To: shang@corp.mot.com
  9. Organization: Motorola, Inc., Software Research and Development, Rolling Meadows, IL. 60008
  10. References: <1992Jul28.210755.3548@ucc.su.OZ.AU>
  11. Date: Wed, 29 Jul 92 16:24:40 GMT
  12. Lines: 43
  13.  
  14. In article <1992Jul28.210755.3548@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John  
  15. MAX Skaller) writes:
  16. > >
  17. > >> NOW: I want to demonstrate why using RTTI is WRONG in this case,
  18. > >> and why the Species() function is required.    
  19. > >>
  20. > >Remenber, your function Species() IS JUST FOR THE PURPOSE TO PROVIDE RTTI. 
  21. >     Yes. I'm not against having run-time-type information
  22. > available. 
  23.  
  24. See your original statement -- what you want to demonstrate.
  25.  
  26. > >> 
  27. > >> The demonstration is so simple, and applies so generally, I wonder
  28. > >> why I didnt think of it before.
  29. > >> 
  30. > >>     class DOG : Animal { ....
  31. > >>     class HUND : Animal { .. // german programmer
  32. > >> 
  33. > >This is never an execuse. If it is, your Species() function has the same  
  34. > >problem:
  35. > >
  36. > >     char* DOG::Species()
  37. > >        { return "DOG"; }
  38. > >     char* DOG::Species()
  39. > >        { return "HOUND"; }   // german programmer
  40. >     What?? The compiler catches this error: it is a duplicate
  41. > definition.
  42. >
  43. The class DOG can be declared as static in different modules and it is highly  
  44. possible if an Australian and a German work for the same project that is  
  45. separated into many different modules.
  46.  
  47. > Actually, I think downcasting is OK when you already knew what the
  48. > type was, or could have. Then it is just a convenience. And safe.
  49. Then we have not disagreement any more.
  50.  
  51.  
  52. David Shang
  53.  
  54.