Class array with different types at each index

You’re right–I forgot to remove them.

A good practice can be to strive to avoid SELECT TYPE altogether.

In this instance it’s not needed.

program main
   use methods_module, only: method, method_a, method_b
   implicit none

   type :: method_wrapper
     class(method), allocatable :: m
   end type method_wrapper

   type(method_wrapper) :: methods(2)
   integer :: i
   logical :: result

   allocate(methods(1) % m, source=method_a())
   allocate(methods(2) % m, source=method_b())

   do i = 1, size(methods)
      call methods(i)%m%check(result)
      print *, i, result
   end do

end program main
C:\temp>gfortran -ffree-form p.f -o p.exe

C:\temp>p.exe
           1 T
           2 F

Also, consider ELEMENTAL procedures as much as feasible, even with type-bound.

3 Likes

I didn’t know you could do that; great! I may have a few spurious select types in my code that I should revisit.