Cloning (programming): Difference between revisions

Content deleted Content added
more so
Cloning: disambag 'slicing'
Line 34:
</source>
 
C++ objects in general behave like primitive types, so to copy a C++ object one could use the '=' (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 clone() method for your classes, and using pointers. (Note that there is no built in clone() method)
 
A C++ example of object cloning: