warning: returning reference to temporary

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2009-08-27T08:17:26Z Indexed on 2010/04/19 18:43 UTC
Read the original article Hit count: 313

Filed under:
|

I have a function like this

const string &SomeClass::Foo(int Value)
{
    if (Value < 0 or Value > 10)
        return "";
    else
        return SomeClass::StaticMember[i];
}

I get warning: returning reference to temporary. Why is that? I thought the both values the function returns (reference to const char* "" and reference to a static member) cannot be temporary.

© Stack Overflow or respective owner

Related posts about c++

Related posts about references