2014-11-04 44 views
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 
+1

如果你可以发布一个可编译的片段,我会仔细看看,但我太闲了,无法弥补所有的差距,使上面的compilable。 – 2014-11-04 19:55:10

回答

0

你的类型声明已在vecpscal的声明中的语法错误绑定 - 你列出两个程序作为执行绑定。我希望编译器能够诊断这一点。

您列出的错误是由于没有与矢量加真实情况(这是错误类型绑定过程语句中的第二个过程)对应的特定绑定而导致的。

+0

我会尽力的 – Zeus 2014-11-04 20:32:37