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 Programmingtypes and values. <strong>The</strong> programmer does not have to reinvent the wheel for every data type aprocedure or a data structure will encounter.<strong>The</strong> "is a" relationship might help you visualize how polymorphic variables interact withtype extensions. A polymorphic variable is a variable whose data types may vary at run time.Polymorphic entities must be a pointer or allocatable variable or a dummy data object.<strong>The</strong>re are two basic types of polymorphism:procedure polymorphismProcedure polymorphism deals with procedures that can operate on a variety of data types andvalues.data polymorphismData polymorphism deals with program variables that can store and operate on a variety ofdata types and values. You see later that the dynamic type of these variables changes when weassign a target to a polymorphic pointer variable or when we use typed or sourced allocationwith a polymorphic allocatable variable.To declare a polymorphic variable, use the class keyword.Polymorphic VariablesIn this example, the sh object can be a pointer to a shape or any of its type extensions. So, it canbe a pointer to a shape, a rectangle, a square, or any future type extension of shape. As long as thetype of the pointer target "is a" shape, sh can point to it.class(shape), pointer :: shThis second example shows how to declare a pointer p that may point to any object whose type isin the class of types or extensions of the type type(point)type pointreal :: x,yend type pointclass(point), pointer :: p7.2.1. Unlimited Polymorphic EntitiesUnlimited polymorphic entities allow the user to have a pointer that may refer to objects of anytype, including non-extensible or intrinsic types. You can use unlimited polymorphic objectsto create heterogeneous data structures, such as a list object that links together a variety of datatypes. Further, you can use abstract types to dictate requirements for type extensions and howthey interact with polymorphic variables.Unlimited polymorphic entities can only be used as an actual argument, as the pointer or target in a pointerassignment, or as the selector in a SELECT TYPE statement.To declare an unlimited polymorphic variable, use the * as the class specifier. <strong>The</strong> followingexample shows how to declare up as an unlimited polymorphic pointer and associate it with areal target.class(*), pointer :: upreal, target :: x,:up => x<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 123

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

Saved successfully!

Ooh no, something went wrong!