Polymorphic copy: Difference between revisions

Added FreeBASIC
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added FreeBASIC)
 
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}}==
2,127

edits