I have a type with two related procedures (GetAsScalar and GetAsList) as part of a common procedure (GetValue):
type, extends(TObject) :: TKeyword character(len=:), allocatable :: fValue contains procedure, private :: GetAsScalar procedure, private :: GetAsList generic :: GetValue => & GetAsScalar, & GetAsList end type TKeyword
Subroutine Signatures:
subroutine GetAsScalar (this, value, status) !Arguments------------------------------------------------------------- class(TKeyword) :: this class(*), target :: value logical, optional :: status !... end subroutine GetAsScalar subroutine GetAsList (this, value, status) !Arguments------------------------------------------------------------- class(TKeyword) :: this class(*), pointer :: value(:) logical, optional :: status !... end subroutine GetAsList
Internally, the TKeyword object stores the string.
If I try to use it as follows (below), I get a compilation error: "There is no corresponding subroutine for this type of associated common subroutine call"
class(TKeyword), pointer :: key class(*), pointer :: p(:) allocate (integer::p(3)) !Code to read instantiate the TKeyword object call key%GetValue(p, status) select type (p) type is (integer) write (*,*) p end select
If I remove GetASScalar from the general association and make it public, the following code works as expected:
class(TKeyword), pointer :: key class(*), pointer :: p(:) allocate (integer::p(3)) !Code to read instantiate the TKeyword object call key%GetAsList(p, status) select type (p) type is (integer) write (*,*) p end select
When passing a scalar (integer, real, character, etc.), the GetAsScalar procedure is called without problems.
I would like to know why this is happening. What am I missing in this βgeneral thingβ that makes the compiler unable to recognize my routine as a general? Is there a way to make this work? Will there be something related to the usual signature?
I am using Intel Fortran 15.0.1.148