procedure pointer to type bound procedure

procedure pointer to type bound procedure

Hi all

the following construct:

Module ModTestParent
Implicit None
Type :: TestParent
Integer :: i
Procedure(suba), Pointer :: pt => Null()
contains
Procedure, Pass, Public :: a => suba
Procedure, Pass, Pbulic :: b => subb
End Type
Private :: suba, subb
contains
Subroutine suba(this,i)
Implicit None
Class(TestParent), Intent(InOut) :: this
Integer, Intent(In) :: i
this%i=this%i+i
End suba
Subroutine subb(this,i)
Implicit None
Class(TestParent), Intent(InOut) :: this
Integer, Intent(In) :: i
this%i=this%i-i
End subb
End Module
Module ModTestChild
use ModTestParent
Implicit None
Type, extends(TestParent) :: TestChild
Integer :: j
contains
Procedure, Pass :: SetPointer => SubSetPointer
End Type
Private :: SubSetPointer
contains
Subroutine SubSetPointer(this,which)
Implicit None
Class(TesChild), Intent(InOut) :: this
Character(len=*), Intent(In) :: which
Select Case(Trim(AdjustL(which))
Case("add")
this%pt => this%a
Case("substract")
this%pt=>this%b
End SubSetPointer
End Module ModTestChild

this won't compile with the error message: "The procedure target must be a procedure or a procedure pointer."

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The error message you receive pertains to lines 41 and 43 of your code. And indeed, this%a and this%b are neither procedures nor procedure pointers. They're procedure bindings, and these are not permitted on the right hand side of a pointer assignment. You could say

this%pt => subaa

at the price of making subaa public or writing a setter function in module ModTestParent that does this.

Cheers,

Reinhold

 

Hi,

thanks for the hint.

I thought they are procedure pointers.

Cheers

Karl

Leave a Comment

Please sign in to add a comment. Not a member? Join today