1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| module test_class_constructor implicit none
private public :: new_ClassStudent_sub, ClassStudent
type :: ClassStudent integer, private :: id character(len=128), public :: name contains procedure, public, pass :: init => new_ClassStudent_sub2 final :: delete_ClassStudent end type ClassStudent interface ClassStudent module procedure new_ClassStudent_fun end interface ClassStudent contains type(ClassStudent) function new_ClassStudent_fun(id, name) integer, intent(in) :: id character(len=*), intent(in) :: name continue write (*,*) "Initial Student ", new_ClassStudent_fun%id, ": ", & trim(new_ClassStudent_fun%name) new_ClassStudent_fun%id = id new_ClassStudent_fun%name = trim(name) write (*,*) "Creating Student ", new_ClassStudent_fun%id, ": ", & trim(new_ClassStudent_fun%name) end function new_ClassStudent_fun subroutine delete_ClassStudent(this) type(ClassStudent), intent(inout) :: this continue write (*,*) "Deleting Student ", this%id, ": ", trim(this%name) end subroutine delete_ClassStudent subroutine new_ClassStudent_sub(id, name, new_Student) integer, intent(in) :: id character(len=*), intent(in) :: name type(ClassStudent), intent(inout) :: new_Student continue write (*,*) "Initial Student ", new_Student%id, ": ", & trim(new_Student%name) new_Student%id = id new_Student%name = trim(name) write (*,*) "Creating Student ", new_Student%id, ": ", & trim(new_Student%name) end subroutine new_ClassStudent_sub subroutine new_ClassStudent_sub2(this, id, name) integer, intent(in) :: id character(len=*), intent(in) :: name class(ClassStudent), intent(inout) :: this continue write (*,*) "Initial Student ", this%id, ": ", trim(this%name) this%id = id this%name = trim(name) write (*,*) "Creating Student ", this%id, ": ", trim(this%name) end subroutine new_ClassStudent_sub2 end module test_class_constructor
|