Topic: temporary data passed by reference
Author: Vincent Finn <1@2.com.cos.agilent.com>
Date: Thu, 25 Apr 2002 17:39:00 GMT Raw View
as long as it is "const string&" it'll be fine
the compiler will take care of it
Bard Tison wrote:
> Is it permissible to pass a temporary variable as a reference parameter?
>
> For instance, if I have a function
>
> void some_function ( const string & s )
> { /* do something */ }
>
> may I call it (using standard C++) using
>
> some_function ( "Greetings" );
> or some_function ( string("Greetings") );
>
> where a the string literal is converted to a temporary string?
>
> This seems to work on some compilers but not on others.
>
> ---
> [ 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 ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Thu, 25 Apr 2002 23:33:45 GMT Raw View
Bard Tison wrote:
>
> Is it permissible to pass a temporary variable as a reference parameter?
>
> For instance, if I have a function
>
> void some_function ( const string & s )
Only if the reference is 'const', as it is in this case.
....
> This seems to work on some compilers but not on others.
The rules were changed a few years ago; not every implementation has the
new rules implemented correctly.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: c379@yahoo.com (Bard Tison)
Date: Thu, 25 Apr 2002 16:56:34 GMT Raw View
Is it permissible to pass a temporary variable as a reference parameter?
For instance, if I have a function
void some_function ( const string & s )
{ /* do something */ }
may I call it (using standard C++) using
some_function ( "Greetings" );
or some_function ( string("Greetings") );
where a the string literal is converted to a temporary string?
This seems to work on some compilers but not on others.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]