- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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."
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
thanks for the hint.
I thought they are procedure pointers.
Cheers
Karl
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page