home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16812 < prev    next >
Encoding:
Text File  |  1992-11-24  |  2.8 KB  |  57 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!sierra!mcgrant
  3. From: mcgrant@rascals.stanford.edu (Michael C. Grant)
  4. Subject: Re: Template functions as class members
  5. In-Reply-To: mat@mole-end.matawan.nj.us's message of Sun, 22 Nov 1992 19:15:02 GMT
  6. Message-ID: <MCGRANT.92Nov23103044@rascals.stanford.edu>
  7. Sender: usenet@EE.Stanford.EDU (Usenet)
  8. Organization: Information Systems Laboratory, Stanford University
  9. References: <1ej5hqINN1lb@cardamom.compnews.co.uk>
  10.     <1992Nov22.191502.1156@mole-end.matawan.nj.us>
  11. Date: 23 Nov 92 10:30:44
  12. Lines: 43
  13.  
  14. In article <1992Nov22.191502.1156@mole-end.matawan.nj.us>
  15. mat@mole-end.matawan.nj.us writes:
  16.  
  17.    In article <1ej5hqINN1lb@cardamom.compnews.co.uk>, rogera@compnews.co.uk (Roger Allen) writes:
  18.    > ... is it possible to have template functions as class member functions?
  19.    > I've tried it ... but it complains at the syntax ... I sat and pondered
  20.    > this and can't think why this shouldn't be possible.
  21.    Sorry, no, you can't.  But remember that every member function of a template
  22.    class IS a template.
  23.    Oh, why not?  Well, for one thing a user can provide an explicit version
  24.    for any templated function.  Since the member function has access to the
  25.    class's private parts, this would allow anyone to write a function that
  26.    would violate encapsulation without any changes to or actions with the
  27.    class header.
  28.    Think about it.
  29. (Thanks for the arrogant tone, by the way)
  30.  
  31. That's not a good enough reason, in my opinion. I can perform exactly that
  32. abuse with non-templated functions by writing my own implementations of
  33. private member functions (even adding some of my own to the header) and
  34. linking them in with my main program. So, are you telling me I shouldn't
  35. be allowed to keep a class's source code in more than one file, since I
  36. can access private variables in that fashion?
  37.  
  38. I'm guilty of similar abuses already, for example. I hate the way that AT&T
  39. wrote their <complex.h> header, (I've said so before on the net), and I
  40. have completely re-written it to my specifications, making .re and .im
  41. public, removing all of the constructors so I can put complexes into a
  42. union (perhaps my BIGGEST complaint), and adding new member functions. I'm
  43. proud of it, too, because I can maintain the ORGANIZATION that class
  44. structures provide without forcing myself to accept another class
  45. designer's shortcomings (which, of course, are always in the eye of the
  46. beholder).
  47.  
  48. (Time for a flame!) C++'s attempt at information hiding is SUCH a joke...
  49. Why do people insist on intercepting every possible 'abuse' by lopping off
  50. a portion of the language's functionality? I don't need some OO
  51. ultra-purist tying my hands behind my back in the name of true OO design...
  52.  
  53. Thanks for listening!
  54. Michael C. Grant
  55. --
  56. "Long hair, short hair--what's the difference once the head's blowed off?" (?)
  57.