- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to call a base version of an overridden type-bound procedure.
This can be done by using CALL ext%base%A(....)
However, this also "casts" (I don't know the proper word in FORTRAN2003) the passed argumentinto the base type.
This has the effect, that, if e.g. the subroutine A in the base calls another type-bound procedure, it actually calls the type-bound procedure of the base rather than the overrided version in extension.
Is there any possiblity to call a overriden subroutine of the base type, but provide the extended type as the passed argument?
See code below for an example. In this case, I would like to have ABase actually call BExtension rather than BBase.
regards,
Thomas
This can be done by using CALL ext%base%A(....)
However, this also "casts" (I don't know the proper word in FORTRAN2003) the passed argumentinto the base type.
This has the effect, that, if e.g. the subroutine A in the base calls another type-bound procedure, it actually calls the type-bound procedure of the base rather than the overrided version in extension.
Is there any possiblity to call a overriden subroutine of the base type, but provide the extended type as the passed argument?
See code below for an example. In this case, I would like to have ABase actually call BExtension rather than BBase.
regards,
Thomas
[fortran] module types type base contains procedure A => ABase procedure B => BBase end type type, extends(base) :: extension contains procedure A => AExtension procedure B => BExtension end type contains subroutine ABase(this) class (base) :: this write (*,*) 'Subroutine ABase has been called' CALL this%B() end subroutine subroutine BBase(this) class (base) :: this write (*,*) 'Subroutine BBase has been called' end subroutine subroutine AExtension(this) class (extension) :: this write (*,*) 'Subroutine AExtension has been called' CALL this%Base%A() end subroutine subroutine BExtension(this) class (extension) :: this write (*,*) 'Subroutine BExtension has been called' end subroutine end module program TypeBoundOverrides use types implicit none ! Variables type (Extension) :: ext ! Body of TypeBoundOverrides call ext%A() end program TypeBoundOverrides [/fortran]
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not aware of a way you can do this. When you call this%Base%A, the passed argument has the type of Base. Perhaps you could do something with the fact that you can bind a single procedure to more than one type. So you might have a single AProc that serves both Base and Extension.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, thanks for your answer.
After posting, I had found a simple solution myself. As it is possible to bind the same procedures in a type using multiple names, I could just do the following:
[fortran] type base contains procedure A => ABase procedure ABase => ABase procedure B => BBase end type [/fortran]
Then, I can call ext%ABase() if A is overloaded, instead of calling ext%base%A()
The only thing that is not pefect is that you have to alter the base class to do this. However, that's not a real issue for our needs at the moment.
regards,
Thomas

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