派生型コンストラクタをC関数で定義します。次の例では、Cインターフェイスを通じてオーバーロードされた加算演算子を定義することができました。構文は非常に似ているAltough、コンストラクタの定義は次のエラーでのgfortran 4.9の下で失敗します。C関数で定義されたFortran派生型コンストラクタ
test.f90:7.52:
module procedure my_module_fortran_new_my_double
1
Error: 'my_module_fortran_new_my_double' at (1) is not a module procedure
グーグルやスタックオーバーフローでの以前の記事を見ているでいくつかの時間を過ごすの後、私は任意の解決策を見つけることができませんでした。誰かが私にこのエラーを引き起こす原因とそれを修正する方法を教えてもらえれば、とても嬉しく思っています。ここで
は私のモジュールのソースコードである:
module my_module
use iso_c_binding
type, bind(c) :: my_double
real(c_double) :: x
end type my_double
interface my_double
module procedure my_module_fortran_new_my_double
end interface
interface operator (+)
module procedure my_module_fortran_add
end interface operator (+)
interface
type(my_double) function my_module_fortran_new_my_double (v) bind (c)
use iso_c_binding
import :: my_double
real (c_double), intent(in) :: v
end function my_module_fortran_new_my_double
type(my_double) function my_module_fortran_add (v1,v2) bind (c)
use iso_c_binding
import :: my_double
type (my_double), intent(in) :: v1,v2
end function my_module_fortran_add
end interface
end module my_module
'module procedure 'を' procedure'に置き換えるとどうなりますか? – francescalus
さて、手続き本体が(a)モジュールにない場合は、モジュール手続きではありません。モジュール内のプロシージャーへのインターフェースを置いてもそれは変わりません。 –