ジェネリック プロシージャ (GetValue) の下に 2 つのバインドされたプロシージャ (GetAsScalar & GetAsList) を持つ型があります。
type, extends(TObject) :: TKeyword
character(len=:), allocatable :: fValue
contains
procedure, private :: GetAsScalar
procedure, private :: GetAsList
generic :: GetValue => &
GetAsScalar, &
GetAsList
end type TKeyword
ルーチンのシグネチャは次のとおりです。
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
内部的に、TKeyword オブジェクトは文字列を格納します。
次の方法で使用しようとすると (下記)、コンパイル エラーが発生します。
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
GetASScalar をジェネリック アソシエーションから削除してパブリックにすると、次のコードが期待どおりに機能します。
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
スカラー (整数、実数、文字など) を渡す場合、GetAsScalar ルーチンは問題なく呼び出されます。
なぜこれが起こっているのか知りたいです。コンパイラがジェネリックの下で私のサブルーチンを認識できないようにするこの「ジェネリックなもの」には何が欠けていますか? これを機能させる方法はありますか?ルーチンの署名に関連するものでしょうか?
Intel Fortran 15.0.1.148 を使用しています