references - C++
Sam Kendall
sam at think.COM
Tue Sep 9 07:51:35 AEST 1986
In article <6027 at alice.uUCp> ark at alice.UucP (Andrew Koenig) writes:
> 1. A reference must always be initialized as it is delcared.
Except of course for formal arguments, which are initialized by their
actuals.
> 3. Therefore, the initializer for a reference must be an lvalue.
C++ Ref Man 3.6.3:
If the initializer for a reference to type T is not an lvalue an
object of type T will be created and initialized with the
initializer. The reference then becomes a name for that object.
This is also the semantics of Fortran argument passing, and I'm sure
people calling Fortran from C++ are very happy -- `sin(2.3)', if `sin'
is a Fortran function, works!
> char c;
> char &cr = &c; /* illegal -- &c is not an lvalue */
The last line is illegal because `&c' has the wrong type, not because
it is an rvalue.
---
Sam Kendall sam at Think.COM
Thinking Machines Corp. ihnp4!think!sam
More information about the Comp.lang.c
mailing list