我有两个例程,它们的区别仅在于参数的顺序,但我想通过接口使用它们,以便在调用时根据参数的顺序调用正确的例程。编译器抱怨它无法区分它们,我的猜测是因为如果我在调用时使用命名参数的语法,它将不知道要调用哪个。一种解决方法是为参数使用不同的名称,但我想知道是否有一种方法可以禁用命名参数调用样式。
例如,这是我要处理的情况
module Foo
interface Bar
module procedure Bar1
module procedure Bar2
end interface
contains
subroutine Bar1(i,r)
integer, intent(in) :: i
real, intent(in) :: r
print *, "bar1"
end subroutine
subroutine Bar2(r,i)
real, intent(in) :: r
integer, intent(in) :: i
print *, "bar2"
end subroutine
end module
program fuux
use Foo
integer :: i
real :: r
r = 5.0
i = 3
call Bar(i,r) ! note that if I call Bar(i=i, r=r) the compiler cannot disambiguate
! so it will complain at the interface statement
end program