emannion:
if I have a function that returns a reference to an int will that data
be lost when the function goes out of scope
Off hand, I can only think of four instances in which you'd return a
reference from a function:
1: int &Func() { return my_global_var; }
2: int &Func() { static int i; return i; }
3: int &Func() { return *new int; }
4: int &Func(SomeStruct ss) { return ss.i; }
Case 1 deals with global objects
Case 2 deals with static objects within functions
Case 3 deals with dynamically allocated objects
Case 4 deals with getting an object from the argument somehow
They're the "natural" cases that come to mind. Maybe if I thought about
it hard enough for a while, I could come up with another reason for
returning a reference from a function, but none come to mind instantly.
--
Tomás Ó hÉilidhe