Content deleted Content added
add c++ equivalent |
|||
Line 6:
In most programming languages (exceptions include: [[Ruby (programming language)|Ruby]]), [[primitive type]]s such as <code>double</code>, <code>float</code>, <code>int</code>, <code>long</code>, etc. simply store their values somewhere in the computer's memory (often the [[call stack]]). By using simple assignment, you can copy the contents of the variable to another one:
Copying primitive types in Java or C++:
<source lang="java">
int original = 42;
Line 23:
copy = original; // does not copy object but only its reference
</source>
The object is not duplicated, the variables 'original' and 'copy' are actually referring to the same object. In C++, the equivalent code
<source lang="c">
Object* original = new Object();
Object* copy = NULL;
copy = original;
</source>
makes it clear that it is a ''pointer'' to the object being copied, not the object itself.
==Cloning==
|