Fortran OOP运算符(+;)

Fortran OOP运算符(+;),oop,fortran,operator-keyword,Oop,Fortran,Operator Keyword,我正在对向量模块中使用的运算符(+)进行编码,并得到以下错误 在内部,我调用了一个操作符,它错误地获取了一些其他函数 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(

我正在对向量模块中使用的运算符(+)进行编码,并得到以下错误 在内部,我调用了一个操作符,它错误地获取了一些其他函数

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

您的类型声明在
vecpscal
绑定的声明中有语法错误-您列出了两个实现绑定的过程。我希望编译器能够对此进行诊断


您列出的错误是由于缺少与vector plus real case(这是错误的类型绑定过程语句中的第二个过程)对应的特定绑定造成的。

如果您可以发布可编译的片段,我将仔细查看,但我太空闲了,无法填补所有空白,无法使上述内容可编译。