File tree Expand file tree Collapse file tree 1 file changed +40
-3
lines changed Expand file tree Collapse file tree 1 file changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -5,17 +5,36 @@ module poly_type
55implicit none (type, external )
66
77type, abstract :: base
8- integer (c_int) :: A, C
8+
9+ integer (c_int) :: A, C
10+
11+ contains
12+
13+ procedure (constructor), deferred :: init
14+
915end type base
1016
1117type, extends(base) :: vthree
12- integer (c_int) :: B = 3
18+ integer (c_int) :: B
19+
20+ contains
21+ procedure :: init = > init_three
1322end type vthree
1423
1524type, extends(base) :: vfour
16- integer (c_int) :: B = 4
25+ integer (c_int) :: B
26+ contains
27+ procedure :: init = > init_four
1728end type vfour
1829
30+
31+ abstract interface
32+ subroutine constructor (self )
33+ import base
34+ class(base), intent (inout ) :: self
35+ end subroutine constructor
36+ end interface
37+
1938contains
2039
2140
@@ -40,9 +59,27 @@ subroutine init_type(xtype, xC) bind(C)
4059 error stop " unknown init type"
4160 end select
4261
62+ x% C = 0
63+
64+ call x% init()
65+
4366end subroutine init_type
4467
4568
69+ subroutine init_three (self )
70+ class(vthree), intent (inout ) :: self
71+
72+ self% B = 3
73+ end subroutine
74+
75+
76+ subroutine init_four (self )
77+ class(vfour), intent (inout ) :: self
78+
79+ self% B = 4
80+ end subroutine
81+
82+
4683function assoc_type (xtype , xC ) result(x)
4784 integer (c_int) :: xtype
4885 type (C_PTR), intent (inout ) :: xC
You can’t perform that action at this time.
0 commit comments