把 AbsVect_Fn 设置为 private 就好了。
一般,OOP的模块,都默认 private,然后把需要的 public
也可以双绑定,即绑定类的过程,也 overloading intrinsic function
这样
write(*,'(2dt"(3f6.2)")') abs(a) , a%abs()
都可以使用
[Fortran] 纯文本查看 复制代码 Module VectClass
Implicit None
private
TYPE , public :: Vect
Real(8) ,Private :: x
Real(8) ,Private :: y
Real(8) ,Private :: z
Contains
Procedure :: set
Procedure,pass(ThisVect),Private :: VectMulScal_Fn , ScalMulVect_Fn , VectMulVect_Fn
Generic, Public :: operator (*) => VectMulScal_Fn , ScalMulVect_Fn , VectMulVect_Fn
Procedure :: writef
Generic :: write(formatted) => writef
Procedure :: abs => AbsVect_Fn
End TYPE
public :: abs
interface abs
module procedure AbsVect_Fn
end interface
contains
function AbsVect_Fn (ThisVect)
type(Vect) :: AbsVect_Fn
class(Vect) :: ThisVect
AbsVect_Fn = Vect( abs(ThisVect%x) , abs(ThisVect%y) , abs(ThisVect%z) )
end function AbsVect_Fn
|