问题
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