Edit: wrong answer ! (I need to go back to school ;-) )
As Bill pointed out local variables are returned by value... I was merely trusting the compiler's alleged error message, and dove right in! Apologies to the group.
Now... in that light, the OP's question doesn't seem to make sense (unless it's something to do with ClassName or some other type I need to learn about), so I'd better shut-up and make way for those who know...
In fairness, my heavy C/C++ coding days are behind me and I never used nor needed return by value for types other than ints, longs and such...
Your logic seem to require the creation of a new ClassName object. This will therefore need to be disposed of, when you are done needing it.
Your first attempt is, thankfully, caught as incorrect by the compiler because the new object is stored in a location that will become invalid when the function returns (local variables are put on the stack and this makes it for a convenient place to have "stuff", without worrying about disposing of it, but of course this storage is only valid for the function where the variable is declared an any function that is called from it.)