10.07.2015 Views

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Object Oriented Programming<strong>The</strong> declared type of the source= must be the same or a type extension of the allocate argument(e.g., als).subroutine init(sh)class(shape) :: shclass(shape), allocatable :: alsallocate(als, source=sh) ! als becomes a clone of sh:end subroutine7.4.4. Unlimited Polymorphic ObjectsData polymorphism using derived types and their type extensions satisfies most applications.However, sometimes you may want to write a procedure or a data structure that can operateon any type, including any intrinsic or derived type. As described in the section on procedurepolymorphism, F2003 provides unlimited polymorphic objects.Here are some examples of unlimited polymorphic objects:subroutine init(sh)class(*) :: sh ! unlimited polymorphic dummy argumentclass(*), pointer :: p ! unlimited polymorphic pointer variableclass(*), allocatable:: als ! unlimited polymorphic allocatable variableend subroutineYou use the class(*) keyword to specify an unlimited polymorphic object declaration. <strong>The</strong>operations for unlimited polymorphic objects are similar to those in the preceding section for"limited" polymorphic objects. However, unlike "limited" polymorphic objects, their "unlimited"counterparts can take any F2003 type.<strong>The</strong> following example illustrates unlimited polymorphic objects that can be used with procedurepolymorphism:subroutine init(sh)class(*) :: shselect type(sh)type is (shape): ! shape specific codetype is (integer): ! integer specific codetype is (real): ! real specific codetype is (complex): ! complex specific codeend selectend subroutineSimilarly, you can assign any pointer or target to an unlimited polymorphic pointer, regardless oftype.<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 139

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!