Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module streams
- type :: iostream
- character(16), private :: name = 'null'
- contains
- final :: ios_close
- procedure :: read => ios_read
- end type
- interface iostream
- module procedure :: ios_open
- end interface
- contains
- function ios_open(name) result(self)
- type(iostream) :: self
- character(*), intent(in) :: name
- self%name = name
- write(*,*) "iostream open "//self%name
- end function
- subroutine ios_close(self)
- type(iostream) :: self
- write(*,*) "iostream close "//self%name
- end subroutine
- subroutine ios_read(self)
- class(iostream), intent(in) :: self
- write(*,*) "iostream read "//self%name
- end subroutine
- end module
- program main
- use streams
- call test
- contains
- subroutine test
- ! If this were in main directly, destructor of 'A' not required to fire.
- type(iostream) :: s
- s = iostream('A')
- call do_stuff(iostream('B'))
- call do_stuff(iostream('C'))
- end subroutine
- subroutine do_stuff(s)
- type(iostream), intent(in) :: s
- call s%read()
- end subroutine
- end program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement