问题描述
如何在Fortran中声明私有函数?
How do I declare a private function in Fortran?
推荐答案
这只适用于Fortran 90模块。在模块声明中,您可以使用public和private关键字指定变量和例程列表的访问限制。我通常发现最初使用private关键字很有用,它指定模块中的所有内容都是私有的,除非明确标记为public。
This will only work with a Fortran 90 module. In your module declaration, you can specify the access limits for a list of variables and routines using the "public" and "private" keywords. I usually find it helpful to use the private keyword by itself initially, which specifies that everything within the module is private unless explicitly marked public.
在下面的代码示例中,subroutine_1 ()和function_1()可以通过必要的use语句从模块外部访问,但任何其他变量/子例程/函数都将是私有的。
In the code sample below, subroutine_1() and function_1() are accessible from outside the module via the requisite "use" statement, but any other variable/subroutine/function will be private.
module so_example
implicit none
private
public :: subroutine_1
public :: function_1
contains
! Implementation of subroutines and functions goes here
end module so_example
这篇关于Fortran中的私有函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!