Fortran Coder

查看: 10705|回复: 7
打印 上一主题 下一主题

[讨论] 子类模块为何不能重用父类模块的抽象接口?

[复制链接]

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
楼主
发表于 2019-7-29 22:27:09 | 显示全部楼层
赞,mark 码一下

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
沙发
发表于 2019-8-2 15:42:56 | 显示全部楼层
我重现了一下,其实代码上的问题,个人感觉不在类的继承上。而在于printSum上。

module m_father
  implicit none
  private
  type,public :: t_father
     procedure(temp),nopass,pointer :: p
  end type t_father

  abstract interface
     function temp(a) result(out)
       implicit none
       integer,intent(in) :: a
       integer :: out
     end function temp
  end interface
end module m_father

module m_son
  use m_father
  implicit none
  private

  type,extends(t_father),public :: t_son
     integer :: a
  end type t_son
end module m_son

program main
  use m_son
  implicit none

  type(t_son) :: one
  one%p=>jiecheng
  print*,one%p(5)

contains
  function jiecheng(a) result(out)
    implicit none
    integer,intent(in) :: a
    integer :: out

    integer :: i

    out=1
    do i=2,a
       out=out*a
    end do
  end function jiecheng
end program main

我测试了,这样是没有问题的

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
板凳
发表于 2019-8-3 12:32:27 | 显示全部楼层
weixing1531 发表于 2019-8-2 21:25
你的接口是静态方法,子类没有重写父类方法
我的接口是实例方法,子类重写了父类方法,抽象接口作为实例方 ...

个人感觉和重载没有关系,关键在于这是两个文件,而且有private属性,那么sub的定义只在super_class内有效。sub_class模块里的过程printsum是不知道pp的原型是什么的。你可以在sub_class内,把sub的名字改成其他,一样能通过。
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-4 02:30

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表