我知道您可以使用抽象类型制作通用过程,例如:
但是我可以用下面的代码做同样的事情吗?
module proc_mod
public :: forced,ideal
interface forced; module procedure forced1; end interface
interface forced; module procedure forced2; end interface
contains
function forced1() result(forced)
implicit none
integer:: forced
forced = 1
end function
function forced2(t) result(forced)
implicit none
integer,intent(in) :: t
integer:: forced
forced = t
end function
function ideal() result(i)
implicit none
integer:: i
i = 2
end function
end module
program procTest
use proc_mod
implicit none
integer :: n
procedure(forced), pointer:: funPointer => NULL()
write(*,'(A)') "Please enter the type of vortex calculation you wish to use."
read(*,*) n
select case( n )
case( 1 ); funPointer => forced
case( 2 ); funPointer => ideal
case default; funPointer => ideal
end select
write(*,'(A,I3)') "You chose function: ", funPointer()
stop
end program
现在我得到了错误: funPointer 可能不是通用的。我确信有办法解决它,但我不熟悉通用程序。