What part of C ++ creates many "copies" of objects?
1 answer
Compared to other OO languages, C ++ makes heavy use of value semantics. Type code Object B = A;
in many languages โโcreates a new reference, but not a new object. We call this reference semantics. In these languages, you need to write something like Object B = new Object(A)
to make a copy. But with semantics, the meaning Object B = A;
is actually a copy.
The second reason was that C ++ doesn't use garbage collection. This means that you often need a copy of an object to guarantee its lifespan. (Today we have std::shared_ptr
)
+3
source to share