Topic: [Q] Reference initialization


Author: "Gabor Greif" <gabor@datawatch.de>
Date: 1997/11/21
Raw View
Simple question:

Can references be initialized by the "constructor" syntax
as of the FDIS?

I.e. is

void bar(void)
{
 int i(42);
 int& ir(i); // error in VC++ 4.2; accepted by CodeWarrior
 int& iR = i; // accepted by both
}

legal?

It is surely legal in the initializer section of constructors,
I want to know of globals and locals.
My intuition expects it to be OK, since integral types can be
initializeed this way too, but is the standard explicit on this?

 TIA,
 Gabor
---
[ 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                             ]





Author: jsa@edg.com (J. Stephen Adamczyk)
Date: 1997/11/21
Raw View
In article <B099F8BD-23713@192.168.1.8> "Gabor Greif" <gabor@datawatch.de>
writes:
>Can references be initialized by the "constructor" syntax
>as of the FDIS?
>
>I.e. is
>
>void bar(void)
>{
> int i(42);
> int& ir(i); // error in VC++ 4.2; accepted by CodeWarrior
> int& iR = i; // accepted by both
>}
>
>legal?

Yes, the parenthesized form is valid for reference initialization.
This program is valid according to the forthcoming standard.
Reference: 8.5 [dcl.init] of the FDIS.

Steve Adamczyk
Edison Design Group
---
[ 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                             ]