- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
In the past I was successfully able to specify two dummy arguments of a subroutine with the CLASS attribute. However, the attached example code is throwing a compiler error (see in the "class_data" module the ImplementMethod subroutine that overrides the abstract Method subroutine from the abstract data type BaseType). Am I getting this error beacuse I am dealing with abstract data types, abstract methods and overriding procedures? Is such an approach not allowed in Fortran?
I am using the latest version of the Intel Fortran under Windows 7.
Thanks for any help.
Jon
[fortran]module class_surrogate
implicit none
type,abstract :: SurrogateType
end type
end module
module class_a
use class_surrogate
implicit none
type,extends(SurrogateType) :: AType
integer :: a
end type
end module
module class_base
use class_surrogate
implicit none
type,abstract :: BaseType
contains
procedure(abstract_method),pass,deferred :: method
end type
abstract interface
subroutine abstract_method(MyData,SuppData)
import :: BaseType,SurrogateType
class(BaseType) :: MyData
class(SurrogateType) :: SuppData
end subroutine
end interface
end module
module class_data
use class_base
use class_a
implicit none
type,extends(BaseType) :: DataType
integer :: n
integer,allocatable :: i(:)
contains
procedure,pass :: method => ImplementMethod
end type
contains
subroutine ImplementMethod(MyData,SuppData)
class(DataType) :: MyData
class(AType) :: SuppData
!Computations
end subroutine
end module
program main
use class_data
implicit none
!Do something
end[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error message tells you exactly what is wrong. Other than the "passed object" implied argument, all other dummy arguments for overridden procedures must be of the same declared type as that of the original. What you want here is to say class(SurrogateType) in the procedure and use SELECT TYPE to distinguish extensions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The characteristics of the procedure for the binding in the extension don't match the characteristics of the interface of the deferred binding in the parent - the declared type of the second argument differs.
Perhaps change the second argument to be CLASS(SurrogateType) and then use select type to cast things to AType. (The fact that the binding could be called with a second object that is an extension of SurrogateType but not specically AType explains why the requirement in the first paragraph of this post exists).
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page