- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Holle,
As in followed codes, the first parameter of the external function "printi" is the type of "c_t", while, i want to pass the object of its extended type. Is there some way to implement?
module dftype
type:: c_t
integer::j=0
!contains
!procedure::printi
end type
type,abstract,extends(c_t):: cc_t
integer::i=0
!contains
!procedure::printi
end type
contains
type(cc_t) function alloccc()
i = 0
end function
subroutine printi(this,i)
class(cc_t)::this
write(*,*)this%i+ i
end subroutine
subroutine printa(a,i)
!class(cc_t)::this
write(*,*) a+i
end subroutine
subroutine prfun(this,fun,fun2)
interface
subroutine fun(this,i)
import c_t
class(c_t)::this
end
end interface
class(c_t)::this
external::fun2
call fun2(1e0,1)
call fun(this,1)
end subroutine
end module
program main
use dftype
class(cc_t),allocatable::cc1
cc1 = alloccc()
cc1%i=1
call prfun(cc1,printi,printa)
end
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is the right code
module dftype
type:: c_t
integer::j=0
!contains
!procedure::printi
end type
type,abstract,extends(c_t):: cc_t
integer::i=0
!contains
!procedure::printi
end type
contains
type(cc_t) function alloccc()
i = 0
end function
subroutine printi(this,i)
class(c_t)::this
write(*,*)this%j+ i
end subroutine
subroutine printa(a,i)
!class(cc_t)::this
write(*,*) a+i
end subroutine
subroutine prfun(this,fun,fun2)
interface
subroutine fun(this,i)
import c_t
class(c_t)::this
end
end interface
class(c_t)::this
external::fun2
call fun2(1e0,1)
call fun(this,1)
end subroutine
end module
program main
use dftype
class(cc_t),allocatable::cc1
cc1 = alloccc()
cc1%i=1
call prfun(cc1,printi,printa)
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use a Fortran markup box to make it readable.
module dftype
type:: c_t
integer::j=0
!contains
!procedure::printi
end type
type,abstract,extends(c_t):: cc_t
integer::i=0
!contains
!procedure::printi
end type
contains
type(cc_t) function alloccc()
i = 0
end function
subroutine printi(this,i)
class(c_t)::this
write(*,*)this%j+ i
end subroutine
subroutine printa(a,i)
!class(cc_t)::this
write(*,*) a+i
end subroutine
subroutine prfun(this,fun,fun2)
interface
subroutine fun(this,i)
import c_t
class(c_t)::this
end
end interface
class(c_t)::this
external::fun2
call fun2(1e0,1)
call fun(this,1)
end subroutine
end module
program main
use dftype
class(cc_t),allocatable::cc1
cc1 = alloccc()
cc1%i=1
call prfun(cc1,printi,printa)
end

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page