fortran - Fortran 扩展类型重载过程,但使用父过程
问题描述
我想知道是否有可能有一个扩展派生类型重载一个过程但仍然设法调用“父”过程。
类似的东西(不起作用,无限递归)
module parent_class
implicit none
private
type,public,abstract :: parent
contains
procedure,pass(self) :: sub
end type
contains
subroutine sub(self)
class(parent),intent(inout) :: self
! Do something here
write(*,*) 'in parent'
end subroutine
end module
module child_class
use parent_class, only: parent
implicit none
private
type,public,extends(parent) :: child
contains
procedure,pass(self) :: sub
end type
contains
subroutine sub(self)
class(child),intent(inout) :: self
! do something here
! ...
write(*,*) 'in child'
call self%sub() ! < this is the parent procedure
end subroutine
end module
program main
use child_class
implicit none
type(child) :: my_child
call my_child%sub()
end program
一种解决方案是在模块sub
中公开可用并在parent_class
模块中使用它,child_class
但我想知道其他解决方案。
解决方案
推荐阅读
- discord.js - 这个 TypeError 正常吗?
- jupyter-notebook - ipywidgets 按钮的图标在 Google colab 中不起作用
- mysql - 我正在尝试创建一个 mysql 触发器,但不能,不知道错误是什么
- ruby-on-rails - 如何处理 Rails 中特定于环境的设置?
- gitlab - 如何在 GitLab CI 上的多项目管道中运行作业到作业的链接
- ios - 滑动单元格以从 Core Data 更改当前单元格内的值
- excel - 我可以在没有 VBA 的情况下连接数组的每个值吗?
- asp.net-core - 我可以强制 MVC-6-Grid 理解字段上的数据注释吗
- php - 从正则表达式中排除符号 [PHP]
- windows - Excel 2010 COUNTIF():您键入的公式包含错误