Re: std::string reference initialized with string literal
On Mar 3, 6:54 pm, "Daniel Kr?gler" <daniel.krueg...@googlemail.com>
wrote:
On 3 Mrz., 15:59, "James Kanze" <james.ka...@gmail.com> wrote:
Something like:
char const& mystring[ 12 ] = "Hello world" ;
would work, though. (At least, I think it would.
I guess that should be written as:
char const (&mystring)[ 12 ] = "Hello world";
Yes. I don't know what I was thinking of.
or does there exist a syntactic trick which works
without parentheses in this situation?
typedef's:
typedef char const String12[ 12 ] ;
String12& myString = "Hello, world" ;
(Untried, but I think it should work.)
A temporary is created. There are a few special cases where the
lifetime of a temporary is extended: when a reference is
initialized with a temporary, the lifetime of that reference is
extended to the lifetime of the reference.
Just nitpicking, because I know you are aware of it:
"[..] the lifetime of that *temporary* is extended to the lifetime
of the reference"
Yes. It's actually a typo in my text: extending the lifetime of
the reference to the lifetime of the reference doesn't mean
anything.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]