Clicky
Showing changes from revision #1 to #2:
(追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)
(削除) Inheritance (削除ここまで)(追記) Objects (追記ここまで)(削除) example (削除ここまで)(追記) example: (追記ここまで)
module my_classes
implicit none
type, public :: class_cinteger :: c
end type class_c(削除)
(削除ここまで)(追記) (追記ここまで)(削除)
(削除ここまで)(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)
type :: class_a
type(class_c) :: objc
integer :: a
contains
procedure :: suba
end type
contains
subroutine suba(this,n)
class(class_a),intent(INOUT) :: this
integer n
print *,(追記) "this is sub input value:" (追記ここまで)(追記) , (追記ここまで)n
print *,(追記) "this is attribute a from class a:" (追記ここまで)(追記) , (追記ここまで)(追記) this (追記ここまで)(追記) % (追記ここまで)(追記) a (追記ここまで)(追記)
(追記ここまで)(追記) print (追記ここまで)(追記) (追記ここまで)(追記) *, (追記ここまで)(追記) "this is attribute c from object c: " (追記ここまで)(追記) , (追記ここまで)this%objc%c
end subroutine suba
end module my_classes
Program myprog
use my_classes
implicit none
type(class_a) :: my_a
my_a%a=11
my_a%objc%c=111
call my_a%suba(10)
end program myprog
(削除) this (削除ここまで)(追記) output: (追記ここまで)(削除) is (削除ここまで)(削除) a (削除ここまで)(削除) simple (削除ここまで)(削除) Object (削除ここまで)(削除) Oriented (削除ここまで)(削除) Program (削除ここまで)(削除) and (削除ここまで)(削除) it (削除ここまで)(削除) is (削除ここまで)(削除) valid (削除ここまで)(削除) for (削除ここまで)(削除) intel (削除ここまで)(削除) fort (削除ここまで)(削除) 12.0.3 (削除ここまで)(追記)
(追記ここまで)(追記) this is sub input value: 10 (追記ここまで)(追記)
(追記ここまで)(追記) this is attribute a from class a: 11 (追記ここまで)(追記)
(追記ここまで)(追記) this is attribute c from object c: 111 (追記ここまで)(追記)
(追記ここまで)
(削除) in (削除ここまで)(追記) this (追記ここまで)(削除) order (削除ここまで)(追記) program (追記ここまで)(削除) to (削除ここまで)(追記) is (追記ここまで)(削除) make (削除ここまで)(追記) valid (追記ここまで)(削除) an (削除ここまで)(追記) for (追記ここまで)(削除) attribute (削除ここまで)(追記) intel (追記ここまで)(削除) or (削除ここまで)(追記) fortran (追記ここまで)(削除) a (削除ここまで)(追記) 12.0.3 (追記ここまで)(削除) procedure (削除ここまで)(削除) private (削除ここまで)(削除) you (削除ここまで)(削除) have (削除ここまで)(削除) to (削除ここまで)(削除) declare (削除ここまで)(削除) it (削除ここまで)(削除) as (削除ここまで)(削除) integer,private (削除ここまで)(削除) :: (削除ここまで)(削除) attr (削除ここまで)(削除) or (削除ここまで)(削除) procedure,private (削除ここまで)(削除) :: (削除ここまで)(削除) sub (削除ここまで)(追記)
(追記ここまで)
in order to make an attribute or a procedure private
you have to declare it as
integer,private :: attr
or
procedure,private :: sub
Simple inheritance:
(追記ここまで)(追記) (追記ここまで)(追記)
module my_classes
implicit none
type, public :: class_c
integer :: c
contains
procedure,private :: subc
end type class_c
type,extends(class_c) :: class_a
integer :: a
contains
procedure :: suba
end type
contains
subroutine suba(this,n)
class(class_a),intent(INOUT) :: this
integer n
print *,"this is sub input value:",n
print *,"this is attribute c from inherit class c:",this%c
end subroutine suba
subroutine subc(this)
class(class_c),intent(INOUT)::this
print *,"private subc"
end subroutine subc
end module my_classes
Program myprog
use my_classes
implicit none
type(class_a) :: my_a
my_a%a=12
my_a%c=456
call my_a%suba(10)
end program myprog
(追記ここまで)(追記)
(追記ここまで)(追記) output:
this is sub input value: 10
this is attribute c from inherit class c: 456
class_a inherits class_c and we can see the attribute c from
suba by printing this%c
Author Nikolaos J. Hatzopoulos