home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: Proposal: static T& function argument
- Message-ID: <1992Sep2.040640.406@frumious.uucp>
- Date: Wed, 2 Sep 1992 04:06:40 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <1992Aug30.000250.12486@tfs.com>
- Organization: None
- Lines: 41
-
- eric@tfs.com (Eric Smith) writes:
- |Here is another proposal that might simplify the issue about
- |lifetime of temporaries. If a function formal argument is
- |specified as static T& the programmer doesn't want any calls
- |using references to temporaries. The "static" in the static T&
- |in that context tells the compiler to issue an error message
- |at compile time whenever anyone tries to call that function with
- |a temporary. This allows the function to safely return a
- |reference or pointer to the static T& argument knowing it can't
- |be a temporary.
-
- I like this idea.
-
- It doesn't solve all the problems, but it should solve quite a few.
- Above all, it's simple.
-
- Some comments, though:
-
- 1) One would only worry about arguments of the type 'const static T&',
- since a reference to non-const can't be bound to a temporary.
-
- 2) It should also be possible to apply this to member functions:
-
- class String {
- public:
- operator const char*() const static;
- };
-
- (This could also apply to non-const member functions.)
-
- 3) Some keyword other than static should be used, or perhaps a
- completely different syntax. The static keyword already has
- too many meanings and although there's no syntactic problem
- in the use of static for String::operator const char*() above,
- it would be just too confusing to have two different meanings
- for "static member function".
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-