home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12944 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  1.8 KB

  1. Path: sparky!uunet!usc!sol.ctr.columbia.edu!caen!uakari.primate.wisc.edu!ames!agate!forney.berkeley.edu!jbuck
  2. From: jbuck@forney.berkeley.edu (Joe Buck)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: a few rookie questions about testing for CLASSS membership.
  5. Message-ID: <17hdhdINNgjv@agate.berkeley.edu>
  6. Date: 27 Aug 92 02:09:49 GMT
  7. References: <1992Aug25.204448.15682@cs.wisc.edu>
  8. Organization: U. C. Berkeley
  9. Lines: 36
  10. NNTP-Posting-Host: forney.berkeley.edu
  11.  
  12. In article <1992Aug25.204448.15682@cs.wisc.edu> roth@ordin.cs.wisc.edu (Bill Roth) writes:
  13. >
  14. >I'm a relative rookie to C++, though not to OOP (due to many moons of
  15. >programming in Objective-C).
  16.  
  17. Learning C++ won't be just a matter of learning new syntax in that case.
  18. C++ is a strongly typed language; Objective-C is not.  There's a tradeoff
  19. in this; C++ will catch many more errors at compile time, but certain
  20. things are more difficult to do.
  21.  
  22. >1. I have a pointer p to some object. How do I test if p is a member
  23. >of the CLASS a.
  24.  
  25. There's no builtin way to do this, and programs that depend on the ability
  26. to do so are against the C++ philosophy.  If you must do it (and sometimes
  27. you must) you can add a method that returns the type.
  28.  
  29. >2. Is there a way to test if p, which is a pointer to an object, can
  30. >test if p can execute method m?
  31.  
  32. Since C++ is a strongly typed language, your program fails to compile if p
  33. cannot execute method m.
  34.  
  35. To understand the distinction between the C++ model of types and that of
  36. Smalltalk (which is very close to that of Objective-C), I suggest reading
  37. Chapter 12 of Stroustrup's "The C++ Programming Language, 2nd edition".
  38.  
  39. I'm not going to tell you that C++'s model is better or worse than that of
  40. Smalltalk.  But it's very different; so much so that you're going to have
  41. to "re-learn" a great deal.
  42.  
  43.  
  44.  
  45.  
  46. --
  47. Joe Buck    jbuck@ohm.berkeley.edu
  48.