Thread View: comp.std.c++
1 messages
1 total messages
Started by Damian Conway
Thu, 18 Apr 1996 01:53
Quick question about const ref return types
Author: Damian Conway
Date: Thu, 18 Apr 1996 01:53
Date: Thu, 18 Apr 1996 01:53
40 lines
2031 bytes
2031 bytes
Is the following legal?
const int& positive(const int& value)
{
if (value<0)
{
return 0;
}
else
{
return value;
}
}
If so, I presume it's also valid in the general case:
const ClassType& func(const ClassType& value);
and that the return of a literal generates a temporary which is bound to
the reference returned and persists until the completion of the full
expression enclosing the function call (or the destruction of a reference
variable to which the returned reference is subsequently bound).
I've searched through the April 95 WP for a definitive answer.
8.5.3. [dcl.init.ref] seems to imply this usage is valid (by
analogy to the binding of temporaries to const reference parameters).
damian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
who: Damian Conway email: damian@bruce.cs.monash.edu.au
where: Dept. Computer Science phone: +61-3-565-5184
Monash University fax: +61-3-565-5146
Clayton 3168 quote: "A pessimist is never disappointed."
AUSTRALIA
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads