Overloading functions with Fortran

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:13:39

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!