Fortran Coder

查看: 5031|回复: 1
打印 上一主题 下一主题

[面向对象] 能将其中的部分代码进行抽象吗

[复制链接]

712

帖子

4

主题

0

精华

大师

农村外出务工人员

F 币
607 元
贡献
311 点

新人勋章爱心勋章水王勋章元老勋章热心勋章

楼主
发表于 2016-11-27 10:53:52 | 显示全部楼层
本帖最后由 楚香饭 于 2016-11-27 11:14 编辑

这一问题,根本就不需要抽象类和子类。

[Fortran] 纯文本查看 复制代码
Module MInteger_Array
  implicit none
  private
  type , public :: int_ary
   integer , private              :: iNs   = 0
   integer                        :: Lens = 2!default 2
   integer , private, allocatable :: iAry(:)
   character(len=:) ,private , allocatable :: CAry(:)
  contains
     procedure      , pass        :: SRead_int_ary
     final                        :: SRead_Uninit
  end type int_ary
contains
  Subroutine SRead_int_ary(this , iunit ) 
    class(int_ary), intent(inout) :: this
    integer       , intent(in)    :: iunit
    read(iunit,*) this%iNs
    allocate(this%iAry(this%iNs))
    read(iunit,*) this%iAry
    if ( this%Lens < 1 ) this%Lens = 2
    allocate( character(len=this%Lens)::this%CAry(this%iNs))
    !call SInt_to_2Char(this%iAry, this%CAry)
  End Subroutine SRead_int_ary
  Subroutine SRead_Uninit(this) 
    type(int_ary), intent(inout) :: this
    deallocate(this%iAry,this%CAry)
  End Subroutine SRead_Uninit
End Module

Program main
  use MInteger_Array
  type(int_ary) :: m2p=int_ary(Lens=2) , m3p=int_ary(Lens=3)
  Open(3,File="filename.txt")
  call m2p%SRead_Int_Ary( 3 )
  call m3p%SRead_Int_Ary( 3 )
  Close(3)
End Program main


您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-3 20:14

Powered by Tencent X3.4

© 2013-2024 Tencent

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