[RFC] Constructor patch

Jerry DeLisle jvdelisle@frontier.com
Wed Oct 27 14:41:00 GMT 2010


On 10/26/2010 11:15 PM, Tobias Burnus wrote:
--- snip ---
> $ gfortran test.f90 && ./a.out
> 9
> 42
>
> $ cat test.f90
> module m
> interface cons
> procedure cons42
> end interface cons
> contains
> integer function cons42()
> cons42 = 42
> end function cons42
> end module m
>
> module m2
> type cons
> integer :: j = -1
> end type cons
> interface cons
> procedure consT
> end interface cons
> contains
> type(cons) function consT(k)
> integer :: k
> consT%j = k**2
> end function consT
> end module m2
>
> use m
> use m2, only: cons
> implicit none
> type(cons) :: x

Just a general question.  I think of an OOP constructor has being called when an 
object is instantiated. Here you have a type and not a class.  What is the value 
of x if the assignment is not made below? I assume -1.  Does Fortran have the 
OOP like constructor I am thinking of? (obviously I need to do some more reading)

> integer :: k
> x = cons(3)
> k = cons()
> print *, x%j
> print *, k
> end

Regards,

jerry



More information about the Fortran mailing list