Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

class bound function pointer inheritance

$
0
0

Hi there

I am trying to have a type bound function pointer inherited downhill through the class hierachy.

an example would be:

Module Mod_Bla_1
  Type :: Bla_1
    Procedure(SubGlobal_1), Pointer :: fun=>null()
  contains
    Procedure, Pass, Public :: Init => SubInit
  End type Bla_1
  Abstract Interface
    Subroutine SubGlobal_1(this)
      Import Bla_1
      Class(Bla_1), Intent(InOut) :: this
    End Subroutine SubGlobal_1
  End Interface
  Private :: SubBla1, SubInit
contains
  Subroutine SubInit(this)
    Class(Bla_1), Intent(InOut) :: this
    this%fun=>SubBla1
  end Subroutine SubInit
  Subroutine SubBla1(this)
    Class(Bla_1), Intent(InOut) :: this
  End Subroutine SubBla1
End Module Mod_Bla_1
Module Mod_Bla_2
  use Mod_Bla_1
  Type, extends(Bla_1) :: Bla_2
  contains
    Procedure, Pass, Public :: Init => SubInit
  End type Bla_2
  Private :: SubBla2, SubInit
contains
  Subroutine SubInit(this)
    Class(Bla_2), Intent(InOut) :: this
    this%fun=>SubBla2
  end Subroutine SubInit
  Subroutine SubBla2(this)
    Class(Bla_2), Intent(InOut) :: this
  End Subroutine SubBla2
End Module Mod_Bla_2
Program Test
  use Mod_Bla_1
  use Mod_Bla_2
  Type(Bla_1) :: xb1
  Type(Bla_2) :: xb2
  call xb1%init()
  call xb2%init()
End Program Test

However this does not compile with error message:

The procedure pointer and the procedure target must have matching arguments.
this%fun=>SubBla2

That would require me to write a new pointer for every child class, which would require me to "invent" a naming hierachy in order get it compiled (e.g. "fun_class_bla_1", "fun_class_bla_2") etc.

Is there any chance to get the example working.

Thanks a lot

Cheers


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>