Is this safe?
const int& f()
{
return 1;
}
What I'm trying to do is to return a some value to const &
It is not okay.
Returning reference to a temporary is not okay because accessing it outside the function causes Undefined Behavior.
No, you're returning a reference to a temporary variable - this is not safe. The temporary variable will have been destroyed upon function return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With