Fortran Coder

查看: 10313|回复: 9
打印 上一主题 下一主题

[面向对象] 过程绑定中的通用接口冲突问题

[复制链接]

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
跳转到指定楼层
楼主
发表于 2020-8-10 20:49:24 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 kyra 于 2020-8-11 08:44 编辑

[Fortran] 纯文本查看 复制代码
module m_haha
  implicit none
  type t_haha
     integer :: a
   contains
     procedure :: test1
     procedure :: test2
     procedure :: test3
     generic :: test=>test1,test2,test3
  end type t_haha
contains
  subroutine test1(this,i)
    implicit none
    class(t_haha),intent(inout) :: this
    integer,intent(in) :: i

    this%a=i

    return
  end subroutine test1

  subroutine test2(this,a)
    implicit none
    class(t_haha),intent(inout) :: this
    integer,intent(in) :: a(0:3)

    this%a=sum(a)

    return
  end subroutine
  subroutine test3(this,a)
    implicit none
    class(t_haha),intent(inout) :: this
    integer,intent(in) :: a(3)

    this%a=sum(a)

    return
  end subroutine
end module m_haha

program main
  use m_haha
  implicit none

  type(t_haha) :: one


  call one%test1(1)
  print*,one%a

  call one%test2([0,1,2,3])
  print*,one%a

  call one%test3([1,2,3])
  print*,one%a
end program main

使用gfotran编译报错,错误原因,test2,test3接口冲突
改用pgi编译,正常。

很迷。。。。是我对重载的理解有问题吗?



分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
沙发
 楼主| 发表于 2020-8-11 16:42:42 | 显示全部楼层
vvt 发表于 2020-8-11 08:43
编译器在 generic name 中选择合适的interface procedure 调用。发生在编译时,而不是发生在运行时。
只有 ...

如果输入是a(:),那么出现ambiguous我认,但a(4),a(3)显然在编译的时候是应当可以被确定的。
module中的函数相当于给出了explicit,那么当实际输入变量大小和哑元大小不符合时就会报错,所以,为什么这个重载就不可以?

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
板凳
 楼主| 发表于 2020-8-11 16:45:58 | 显示全部楼层
chiangtp 发表于 2020-8-10 21:50
Windows Absoft/Compaq/Intel/NAG/Silverfrost/NAG/G95 都是
test2,test3接口冲突: "test2" is not disti ...

感谢您回复,看起来PGI自己标准都不一致啊

79

帖子

17

主题

0

精华

专家

齊天大聖

F 币
433 元
贡献
266 点
地板
 楼主| 发表于 2020-8-11 19:25:44 | 显示全部楼层
vvt 发表于 2020-8-11 17:42
你说的“实际输入变量大小和哑元大小不符合时就会报错”,是运行时错误,也是在运行时才做的检查。
但决 ...

我明白你的意思了,十分感谢!
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-3 02:24

Powered by Tencent X3.4

© 2013-2024 Tencent

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