Resolving procedure confusion when using OOP

前端 未结 1 825
自闭症患者
自闭症患者 2021-01-26 10:35

I am writing a vector type in Fortran and am getting very confused.

Suppose I have the following derived type

Type (Vector)
Real :: x, y
Contains  
  Pro         


        
1条回答
  •  孤独总比滥情好
    2021-01-26 11:31

    You are just defining a type-bound procedure xyz%smul that points to vector_smul! The original module procedure vector_smul is not effected!

    To stay in the terminology of the Fortran Standard (2008, ch. 4.5.5), smul is the binding name for the procedure name vector_smul. You still can access the procedure itself.

    You can "rename" the function when using it in the main program:

    Program Test
      Use Vector, only: Vector, smul => vector_smul
      Implicit None
      Real :: c
      Type (Vector) :: va, vb 
      c = smul (va, vb)
    End Program
    

    [Although it is not possible to have the same name for the type different and the module, i.e. not name them both Vector...]

    Take a look at the corresponding topic at the Fortran Wiki...

    0 讨论(0)
提交回复
热议问题