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