Polymorphic copy: Difference between revisions
Content added Content deleted
Line 981: | Line 981: | ||
=={{header|Nimrod}}== |
=={{header|Nimrod}}== |
||
<lang nimrod>type |
<lang nimrod>type |
||
T = object of TObject |
T = ref object of TObject |
||
myValue: string |
myValue: string |
||
S1 = object of T |
S1 = ref object of T |
||
S2 = object of T |
S2 = ref object of T |
||
method speak(x: T) = echo "T Hello ", x.myValue |
method speak(x: T) = echo "T Hello ", x.myValue |
||
Line 999: | Line 999: | ||
echo "Making copy of a as u, colors and types should match" |
echo "Making copy of a as u, colors and types should match" |
||
u.deepCopy(a) |
|||
u = a |
|||
u.speak |
u.speak |
||
a.speak |
a.speak |
||
Line 1,033: | Line 1,033: | ||
Assigning new color to u. Since u,b references same object b's color changes as well |
Assigning new color to u. Since u,b references same object b's color changes as well |
||
S2 Woof Yellow |
S2 Woof Yellow |
||
S2 Woof |
S2 Woof Yellow</pre> |
||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |