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

procedure pointer to type bound procedure

may_ka
Beginner
800 Views

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."

0 Kudos
2 Replies
reinhold-bader
New Contributor II
800 Views

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

 

0 Kudos
may_ka
Beginner
800 Views

Hi,

thanks for the hint.

I thought they are procedure pointers.

Cheers

Karl

0 Kudos
Reply