module base_class type :: base integer(kind = 4) :: n real(kind = 8) :: x procedure(intfc_access_b), pointer, pass(handle) :: access => null() ! access function contains procedure, pass(handle) :: power => base_power end type base interface subroutine intfc_access_b(handle) import :: base class(base) :: handle end subroutine intfc_access_b end interface contains function base_power(handle) result(r) class(base) :: handle r = handle%x**handle%n ! use intrinsic exponentiation operator call handle%access() end function base_power end module base_class module derived_class use base_class type, extends(base) :: derived contains procedure, pass(handle) :: power => derived_power ! procedure(intfc_access_d), pointer, pass(handle) :: access => null() !!! error end type derived interface subroutine intfc_access_d(handle) import :: derived class(derived) :: handle end subroutine intfc_access_d end interface contains function derived_power(handle) result(r) class(derived) :: handle r = exp(handle%n*log(handle%x)) ! use property of power function: y^x = exp(x ln(x)) call handle%access() end function derived_power end module derived_class program main use derived_class type(derived) :: a real(kind = 8) :: y a%access => my_af a%n = 5 a%x = 2 y = a%power() print *, 'y = ', y read * contains subroutine my_af(T) class(base) :: T ! OK ! class(derived) :: T !!! error (would like T to be derived class object) ! defines customizable print function that will be called internally print *, 'n = ', T%n print *, 'x = ', T%x end subroutine my_af end program main