1
我正在編寫矢量模塊中使用的運算符(+),並且出現以下錯誤 內部我正在調用一個運算符,它在出錯時拾取了一些其他函數。Fortran OOP運算符(+)
gfortran -o build/lib/vectors.o -c -ffree-form -g -J./build/lib lib/vectors.f
lib/vectors.f:804.7:
vd = ud + scald
1
Error: Operands of binary numeric operator '+' at (1) are CLASS(vector)/REAL(4)
scons: *** [build/lib/vectors.o] Error 1
scons: building terminated because of errors.
這是代碼。我不確定這個問題是由於綁定是如何聲明的。
Module Vectors
Implicit None
Type :: Vector
Real :: x
Real :: y
Real :: z
Contains
Procedure :: vecp => vector_add
Procedure :: vecpscal => vector_plus_integer, &
vector_plus_real
Procedure, Pass (ub) :: integer_plus_vector
Procedure, Pass (ud) :: real_plus_vector
Generic :: Operator (+) => vecp, vecpscal, &
integer_plus_vector, &
real_plus_vector
End Type Vector
Contains
Function vector_add &
( &
u, v &
) &
Result (w)
!!$ In.
Class (Vector), Intent(in) :: u, v
!!$ Out.
Type (Vector) :: w
w% x = u% x + v% x
w% y = u% y + v% y
w% z = u% z + v% z
End Function vector_add
Function vector_plus_real &
( &
u, scal &
) &
Result (v)
!!$ In.
Class (Vector), Intent(in) :: u
Real, Intent (In) :: scal
!!$ Out.
Type (Vector) :: v
v% x = u% x + scal
v% y = u% y + scal
v% z = u% z + scal
End Function vector_plus_real
Function vector_plus_integer &
( &
ub, scalb &
) &
Result (vb)
!!$ In.
Class (Vector), Intent(in) :: ub
Integer, Intent (In) :: scalb
!!$ Out.
Type (Vector) :: vb
vb% x = ub% x + scalb
vb% y = ub% y + scalb
vb% z = ub% z + scalb
End Function vector_plus_integer
Function real_plus_vector &
( &
scalc, uc &
) &
Result (vc)
!!$ In.
Real, Intent (In) :: scalc
Class (Vector), Intent(in) :: uc
!!$ Out.
Type (Vector) :: vc
vc = uc + scalc
End Function real_plus_vector
Function integer_plus_vector &
( &
scald, ud &
) &
Result (vd)
!!$ In.
Integer, Intent (In) :: scald
Class (Vector), Intent(in) :: ud
!!$ Out.
Type (Vector) :: vd
vd = ud + scald
End Function integer_plus_vector
End Module Vectors
如果你可以發佈一個可編譯的片段,我會仔細看看,但我太閒了,無法彌補所有的差距,使上面的compilable。 – 2014-11-04 19:55:10