This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Warning] When passing const reference and default value


On Mon, Nov 01, 2004 at 05:09:34PM -0500, Mathieu Malaterre wrote:
> Hello,
> 
> 	I was just wondering should the following code (*) produce a warning 
> when being compiled or not? I would tend to say yes, it should. If not 
> could someone explain me how the compiler could produce a string 
> reference out of the default const char * value ?

This is a basic C++ question.  The code is valid and should not produce
a warning.  The initializer for a const reference might require a
conversion; if it does, a temporary is created and the const reference
points to the temporary.  It is quite common to bind C charater strings
to const std::string references.

> void foo(std::string const & s = "bar" )
> {
>   std::cout << s << std::endl;
> }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]