Newbie looking for advice

Operator overloading was a Fortran 90 thing, and the OOP facilities were added in Fortran 2003, so you have two ways to do the same thing, e.g.:

....
    type, public :: qobj
        complex(real64), allocatable :: data(:,:)
    contains
        procedure, private ::  mult_matrix, mult_scalar1, mult_scalar2
        generic :: operator(*) => mult_matrix, mult_scalar1, mult_scalar2
        procedure, private :: write_qobj
        generic :: write(formatted) => write_qobj
    end type
...
contains
....
    subroutine write_qobj(this, unit, iotype, v_list, iostat, iomsg)
        class(qobj), intent(in) :: this
        integer, intent(in) :: unit
        character(*), intent(in) :: iotype
        integer, intent(in) :: v_list(:)
        integer, intent(out) :: iostat
        character(*), intent(inout) :: iomsg
        ....
    end subroutine

In Fortran, type-bound procedure is the fancy way of saying method (i.e., passed object or receiver marked with class, dynamic dispatch, etc.).

This post lists some interesting stuff related to OOP in Fortran.

1 Like