If I dynamically allocate a variable, what do I return?
Return a pointer (a regular one or a smart one, depending on a situation). Do not return a reference to dynamically allocated objects: eventually, you will need to release the memory for the object; the construct delete &someRef
that you would have to use is extremely counterintuitive.
Returning a reference is appropriate when you are returning from a member function, and a reference that you are returning is to a member, or when you are returning a reference to an object that has been passed to your function in the first place.
Why don't just return the variable?
This is a very valid choice as well: returning by value lets you not worry about memory management and object ownership. The biggest obstacle there is the cost of copying. However, their inefficiencies are are often grossly overestimated, leading to premature optimization.