Message from C, C++ discussions

January 2020

— Yep but either the object gets moved or with rtvo (return value optimization) this copy gets eleminated (except maybe for primitives)

Message permanent page

— 

Well we should always stick to the object with which the operator was called. What if multiple exist and we always return cout we might return the wrong object because it was called on something else

— Also what is the lifetime of the newly created copy?

— Depends if it's a deep copy or a shallow copy if I'm not mistaken

— Well, when we return by value, how do we know whether it is deep/shallow?

— If it's a single value being returned that gets stored in some variable it will have the lifetime of the variable

Message permanent page

— It's different for objects and I'm vague on exactly what it does. Lemme find a source

— Http://www.fredosaurus.com/notes-cpp/oop-condestructors/shallowdeepcopy.html

— It depends if it is a pure value or a dynamic allocated object/pointer/reference/rvalue ref

— C++ I suppose? Usually custom copyctor implements deep copy, or if fields are either trivial or have custom copyctors

Message permanent page

— user-provided's the name

— In C++ you don't usually talk in those terms. An object itself can be copyed (deep copy) or moved (transfer all the contents of the objecto to another, leaving the first one empty). A shallow copy is what in C++ we call a reference (kind of), because it's the same object, just with another name

Message permanent page