home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13175 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: Proposal: static T& function argument
  5. Message-ID: <1992Sep2.040640.406@frumious.uucp>
  6. Date: Wed, 2 Sep 1992 04:06:40 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <1992Aug30.000250.12486@tfs.com>
  9. Organization: None
  10. Lines: 41
  11.  
  12. eric@tfs.com (Eric Smith) writes:
  13. |Here is another proposal that might simplify the issue about
  14. |lifetime of temporaries.  If a function formal argument is
  15. |specified as static T& the programmer doesn't want any calls
  16. |using references to temporaries.  The "static" in the static T&
  17. |in that context tells the compiler to issue an error message
  18. |at compile time whenever anyone tries to call that function with
  19. |a temporary.  This allows the function to safely return a
  20. |reference or pointer to the static T& argument knowing it can't
  21. |be a temporary.
  22.  
  23. I like this idea.
  24.  
  25. It doesn't solve all the problems, but it should solve quite a few.
  26. Above all, it's simple.
  27.  
  28. Some comments, though:
  29.  
  30. 1) One would only worry about arguments of the type 'const static T&',
  31.    since a reference to non-const can't be bound to a temporary.
  32.  
  33. 2) It should also be possible to apply this to member functions:
  34.  
  35.       class String {
  36.       public:
  37.          operator const char*() const static;
  38.       };
  39.  
  40.    (This could also apply to non-const member functions.)
  41.  
  42. 3) Some keyword other than static should be used, or perhaps a
  43.    completely different syntax.  The static keyword already has
  44.    too many meanings and although there's no syntactic problem
  45.    in the use of static for String::operator const char*() above,
  46.    it would be just too confusing to have two different meanings
  47.    for "static member function".
  48.  
  49. -- 
  50. Patrick Smith
  51. uunet.ca!frumious!pat
  52. pat%frumious.uucp@uunet.ca
  53.