我想写一个抽象类型
type, abstract :: Vehicle
real, dimension(:), allocatable:: Wheels
contains
procedure (Compute_Weight), deferred :: VehicleWeight
end type Vehicle
那就是我想在数组的抽象类型中有一个占位符,这样它可以在扩展类型中被覆盖或重新定义,比如
type, extends(Vehicle) :: Bike
allocate(Wheels(2))
contains
procedure :: VehicleWeight => BikeWeight
end type Bike
type, extends(Vehicle) :: Car
allocate(Wheels(4))
contains
procedure :: VehicleWeight => CarWeight
end type Car
GCC编译器抱怨(我猜是正确的),我能找到的唯一解决方案就是不在抽象类型中声明可分配函数,而是直接在类型内以正确的大小声明变量。尽管如此,我希望有一种占位符来强制执行 Wheels 描述的基本属性(原型)。我