コンパイラ: ifort バージョン 12.1.5
Fortran コードを書いていて、F2003 の OOP 機能を利用したいのですが、つまずきにぶつかっています。例を要約すると、2 つの派生型 A と B が必要で、それぞれが他方のインスタンスへのポインターを持ちます。Fortran では、モジュール間の循環依存は明示的に禁止されているため、これら 2 つの型は同じモジュールに存在する必要があります。これはコンパイルされます:
module testModule
implicit none
type A
type(B),pointer :: b1
end type A
type B
type(A),pointer :: a1
end type B
contains
[some possibly type-bound procedures]
end module
ここで、これらの型のコンストラクターをいくつか実装して、次のコードを試してみたいと思います。
module testModule
implicit none
type A
type(B),pointer :: b1
end type A
interface A
module procedure A_ctor
end interface
type B
type(A),pointer :: a1
end type B
interface B
module procedure B_ctor
end interface
contains
function A_ctor()
type(A),target :: A_ctor
end function
function B_ctor()
type(B),target :: B_ctor
end function
end module
さて、これはコンパイルされず、エラーがスローされます
これは派生型名ではありません。[B]
上記の5行目。インターフェイスを追加するとエラーがスローされるのはなぜですか? C++ で前方クラス宣言を使用するように、Fortran で派生型の循環依存をどのように処理しますか?