Content deleted Content added
HeyElliott (talk | contribs) |
|||
Line 41:
copyObj = originalObj.clone(); // duplicates the object and assigns the new reference to 'copyObj'
</syntaxhighlight>→
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. (There is no built-in <code>clone()</code> method.)
|