- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to call a parent procedure in a user-defined derived type?
module my_mod implicit none type :: parent_t private integer :: a = 0 contains procedure, public :: print => print_pt end type type, extends(parent_t) :: my_t contains procedure, public :: print => print_mt end type my_t contains subroutine print_pt(this) class(parent_t), intent(in) :: this write(*,'(i0)') this%a end subroutine print_pt subroutine print_mt(this) class(my_t), intent(in) :: this write(*,'(a)') 'My value is' ! How do I call print_pt here? !! call this%print_pt() gives compilation error 6460 end subroutine print_mt end module my_mod
Hopefully the above code is sufficiently explanatory. I have tried a direct call to print_pt but that gives a compiler error
error #6460: This is not a field name that is defined in the encompassing structure. [PRINT_PT]
What is the correct syntax? I'm using Version 16.0.3.207. Thanks.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Definitely:
call this%parent_t%print()
The method name is print - if you want to invoke the underlying routine directly, that is possible too:
call print_mt(this)
or:
call print_pt(this)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent. call this%parent_t%print() works perfectly. Thanks.
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