A well-designed object-oriented system encapsulates the object internally, leaving only two functions to copy the object.
If a new member is added to an object, it must be processed in all constructors and copy functions. Otherwise, a local copy is generated.
If you wantDerived
ClassWriteCopingFunction, you must copy it carefully.Base ClassComponent.
When you compileCopyingFunction is, you must (1) Copy allLocalMember variable (2) Call the appropriateBase ClassOfCopyingFunction.
IfCopyConstructor andCopy assignmentOperator functions have the sameCode, You can use a new function to encapsulate them.
Note:
CopyingMake sure that the function copies "all member variables in the object" and "allBase ClassComponent"
Do not tryCopyingFunction implementationCopyingFunction, you should put the common mechanism into the third function, and there are twoCopyingFunction call.