Parameter passed by const reference returned by const reference.
        Posted  
        
            by Alien01
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Alien01
        
        
        
        Published on 2009-03-20T18:34:43Z
        Indexed on 
            2010/05/04
            22:38 UTC
        
        
        Read the original article
        Hit count: 282
        
c++
Hello,
I was reading C++ Faq Second Edition , faq number 32.08 .
FAQ says that parameter passed by const reference and returned by const reference can cause dangling reference.
But it is ok if parameter is passed by reference and returned by reference.
I got it that it is unsafe in case of const reference but how is it safe in case when parameter is non const reference.
Last line of FAQ says "Note that if a function accepts a parameter by non-const reference (for example, f(string& s)), returning a copy of this reference parameter is safe because a temporary cannot be passed by non-const reference."
Need some insight on this!!
© Stack Overflow or respective owner