How to make reference to the last placed object?

Thanks! I will try C++ way.