Polymorphic copy: Difference between revisions
Added FreeBASIC
(→{{header|TXR}}: New section.) |
(Added FreeBASIC) |
||
(One intermediate revision by one other user not shown) | |||
Line 959:
end program test
</syntaxhighlight>
=={{header|FreeBASIC}}==
FreeBASIC does not support object-oriented programming and polymorphy. However, you can simulate it using user-defined types and procedure pointers.
<syntaxhighlight lang="vbnet">Type T
method As Sub(pthis As T Ptr)
End Type
Type S Extends T
dato As Integer
End Type
Sub TMethod(pthis As T Ptr)
Print "T method"
End Sub
Sub SMethod(pthis As S Ptr)
Print "S method, dato = "; pthis->dato
End Sub
Sub CallMethod(pthis As T Ptr)
pthis->method(pthis)
End Sub
Dim As T tt
tt.method = @TMethod
Dim As S ss
ss.method = @SMethod
ss.dato = 123
Sleep</syntaxhighlight>
{{out}}
<pre>T method
S method, dato = 123</pre>
=={{header|Go}}==
Line 2,245 ⟶ 2,279:
There is no built in 'copy' method - you need to write your own for any class that needs it.
<syntaxhighlight lang="
construct new(name, age) {
_name = name
|