I am confused between :
- returning an object (but then the object is copied from the local variable in the function, which consumes memory)
- returning a pointer (but then you have to remember to delete it, in the calling code, which is weird)
- returning a reference (but this is not possible because this would be a reference to a local variable of the function, which would be deleted as soon as the function ends)
I am looking for the proper way to return an object from a C++ function, in basic C++ (no library handling pointers and freeing memory automatically). I want to know how this is supposed to be done.
Thank you