Overloading functions with Fortran

前端 未结 1 1653
北荒
北荒 2021-02-07 06:23

In Fortran 90, we can overload functions with an interface. However, according to this site, we cannot define these functions with the same arguments name. With gfortran, it doe

相关标签:
1条回答
  • 2021-02-07 06:42

    Your example is perfectly valid. They can be distinguished by the TYPE of the arguments. The names are not important then. In your case the type of the cur argument differs.

    The arguments with the same name can be distinguished by their type, kind or rank (TKR compatibility).

    The point of the referenced article is that you cannot distinguished two specific procedures only by the ORDER of the arguments. It is because the procedures can be called with the keyword arguments in any order. This can be overcomed by using different names for the arguments.

    Otherwise declaring more specific procedures for a generic one with the same names of arguments, but with different types/kinds/ranks is very common and perfectly valid.

    Fortran 2003/2008 adds some more possibilities to generic resolution. It is also possible to distinguish procedures by the pointer/allocatable attribute of their arguments and by the procedure pointer dummy arguments.

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