Call an object method: Difference between revisions
Content added Content deleted
(added Fortran) |
|||
Line 227: | Line 227: | ||
Frisky speak \ => meow ok |
Frisky speak \ => meow ok |
||
Sparky speak \ => woof ok |
Sparky speak \ => woof ok |
||
</lang> |
|||
=={{header|Fortran}}== |
|||
In modern Fortran a "derived type" concept corresponds to "class" in OOP. Such types have "type bound procedures", i.e. static methods. Procedure pointer components depend on the value of the object (so they are object-bound), can be redefined runtime and correspond approx to instances. |
|||
<lang Fortran> |
|||
! type declaration |
|||
type my_type |
|||
contains |
|||
procedure, pass :: method1 |
|||
procedure, pass, pointer :: method2 |
|||
end type my_type |
|||
! declare object of type my_type |
|||
type(my_type) :: mytype_object |
|||
!static call |
|||
call mytype_object%method1() ! call method1 defined as subroutine |
|||
mytype_object%method2() ! call method2 defined as function |
|||
</lang> |
</lang> |
||