you're returning a reference to a local variable, that's your problem, when the function returns 'tmp' goes out of scope and so the reference is to what? An object that no longer exists.
Indeed, the problem is that I've seen doing it that way (creating a temporary object and then returning it) with no problems whatsoever. So this can be done, somehow, but I don't know how, lol.