相关疑难解决方法(0)

带有过程参数的通用类型绑定过程

我正在尝试编写一个通用的类型绑定过程,它将不同的回调函数作为参数。当编译以下代码(使用 ifort 12.1.3)时,我收到以下警告:

module test

type :: a_type
  contains
  procedure :: t_s => at_s
  procedure :: t_d => at_d
  generic :: t => t_s,t_d
end type a_type

abstract interface
  integer function cb_s(arg)
  real(4) :: arg
  end function cb_s

  integer function cb_d(arg)
  real(8) :: arg
  end function cb_d
end interface

contains

subroutine at_s(this,cb)
  class(a_type) :: this
  procedure(cb_s) :: cb 
end subroutine

subroutine at_d(this,cb)
  class(a_type) :: this
  procedure(cb_d) :: cb 
end subroutine

end module test
Run Code Online (Sandbox Code Playgroud)

警告:

compileme.f(27): warning #8449: The type/rank/keyword signature …
Run Code Online (Sandbox Code Playgroud)

fortran fortran2003

5
推荐指数
1
解决办法
2717
查看次数

在Fortran 2003中键入绑定过程重载

我已经用Java编程了几年; 但是,我现在正在学习一门使用Fortran作为示例代码(77标准)的课程.虽然我一直认为Fortran是一种古老的语言,但我决定使用gfortran编译器试用2003标准的最新实现来看看它的优点.到目前为止,我对现代功能感到惊讶,但我遇到了一个问题,下面的例子证明了这个问题.

    module mod1
      type type1
        real :: x
        real :: y
        contains
        procedure :: compute
      end type type1
      contains
      subroutine compute(this)
        class(type1) :: this
        this%y = this%x*2 - 1
        write (*,*) this%x,this%y
      end subroutine
    end module mod1

    module mod2
      type type2
        real :: x
        real :: y
        contains
        procedure :: compute
      end type type2 
      contains
      subroutine compute(this)
        class(type2) :: this
        this%y = this%x - 5
        write (*,*) this%x,this%y
      end subroutine
    end module mod2

    program test
      use mod1
      use mod2 …
Run Code Online (Sandbox Code Playgroud)

oop fortran gfortran fortran2003

4
推荐指数
1
解决办法
1245
查看次数

标签 统计

fortran ×2

fortran2003 ×2

gfortran ×1

oop ×1