Hi guys,
Your typical C++ beginner here. I'm using the renowned Deitel C++: How to program to learn C++. I am my own mentor and here's what I can't comprehend:
What's a Dangling Reference?
According to Deitel C++: How to Program and I quote "Functions can return references, but this can be dangerous. When returning a reference to a variable declared in the called function*, the variable should be declared STATIC within that function. Otherwise, the reference refers to an automatic variable that is discarded when the function terminates; such a variable is said to be "undefined" and the program's behavior would be unpredictable."
*Called function or the function to whom we return e.g main()?
It would be nice if someone could elaborate on what a Dangling Reference is and provide a code example too. I googled but found nothing helpful or comprehensible.
Thank you for your time.