Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Using base class for passing

zp3
Beginner
293 Views

Hi,

I'ld like to ask why it isn't possible to use a base class for passing the object:

module greet_mod

  type, abstract :: GREETER
      character(100) :: name
    contains
      procedure(greet_fun), deferred :: greet
  end type GREETER

  abstract interface
      subroutine greet_fun(this)
        import :: GREETER
        class(GREETER), intent(in) :: this
      end subroutine greet_fun
  end interface

  type, extends(GREETER) :: ENGLISH_GREETER
    contains
      procedure greet => en_greet
  end type ENGLISH_GREETER

contains

  subroutine en_greet(this)
    class(GREETER), intent(in) :: this !won't work
    !class(ENGLISH_GREETER), intent(in), this !works

    write(*,*) 'Hi ',trim(adjustl(this%name))
  end subroutine en_greet

end module greet_mod

program test_greeter
  use greet_mod

  class(GREETER), allocatable :: gtr

  allocate(ENGLISH_GREETER::gtr)
  gtr%name='F03'
  call gtr%greet()
end program test_greeter
error #8262: For a type-bound procedure that has the PASS binding attribute, the first dummy argument must have the same declared type as the type being defined.   [THIS]
  subroutine en_greet(this)
----------------------^

Is this normal behavior?

Thanks in advance!

 

0 Kudos
1 Reply
Steven_L_Intel1
Employee
293 Views

Yes, this is what the standard specifies.

C456 The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object with the same declared type as the type being defined; all of its length type parameters shall be assumed; it shall be polymorphic (4.3.1.3) if and only if the type being defined is extensible (4.5.7). It shall not have the VALUE attribute.

0 Kudos
Reply