In Fortran, when in extension definition, how to set a public procedure into private?

好久不见. 提交于 2019-12-13 18:31:36

问题


Assume I first defined a type A in which a public procedure f is defined, and may also be bonded to A. In another module I have this type extended into B. However, when I use type B, I do not want f to be exposed. By the way, I don't want to use the submod technique.

complement:

Assume type(A) is already defined:

module mA 
type::A
 ...
 contains 
 procedure::f
endtype
endmodule

In another module B, we extend A as:

module mB 
use mA
type,extends(A)::B
 ...
endtype
endmodule

In this module, f may still be used. However, next, in module mC I will use(declare)

type(B)::Ob 

and I wish "call Ob%f()" to be illegal. Or equivalently speaking, I want to ban some of the function when I extend a class.


回答1:


It is hard to understand your descriiption, but if I understand it correctly it is not possible.

Consider you have a variable class(A) :: o. You are allowed to call

call o%f()

class(A) is polymorphic and can be any extended type of A so its dynamic type can be type(B). So B MUST provide publicly accessible procedure f to stay compatible with the parent.



来源:https://stackoverflow.com/questions/47959048/in-fortran-when-in-extension-definition-how-to-set-a-public-procedure-into-pri

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