Cloning (programming): Difference between revisions

Content deleted Content added
rm merge tag for which there is no discussion thread
No edit summary
Line 45:
</source>
 
C++ objects in general behave like primitive types, so to copy a C++ object one could use the '<code>=</code>' (assignment) operator. There is a default assignment operator provided for all classes, but its effect may be altered through the use of [[operator overloading]]. There are dangers when using this technique (see [[Object slicing|slicing]]). A method of avoiding slicing can be implementing a similar solution to the Java <code>clone()</code> method for the classes, and using pointers. (Note that there is no built-in <code>clone()</code> method)
 
A C++ example of object cloning: