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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Object Oriented ProgrammingWith the addition of a "class default" branch, the type is (shape) branch is needed, eventhough it does not perform any additional assignments. Otherwise, this example wouldincorrectly print an error message when sh is of type shape.7.2.5. Procedure Polymorphism with Type-Bound ProceduresDerived types in F2003 are considered objects because they encapsulate data as well asprocedures. Procedures encapsulated in a derived type are called type-bound procedures. <strong>The</strong>following example illustrates how to add a type-bound procedure to shape:type shapeinteger :: colorlogical :: filledinteger :: xinteger :: ycontainsprocedure :: initializeend type shapeF2003 added a contains keyword to its derived types to separate a type's data definitions fromits procedures. Anything that appears after the contains keyword in a derived type must be atype-bound procedure declaration.Syntax of type-bound procedure declaration:PROCEDURE [(interface-name)] [[,binding-attr-list ]::] binding-name[=>procedure-name]At the minimum, a type-bound procedure is declared with the PROCEDURE keyword followedwith a binding-name.<strong>The</strong> binding-name is the name of the type-bound procedure.<strong>The</strong> first option is interface-name.<strong>The</strong> binding-attr-list option is a list of binding-attributes.‣ PASS and NOPASS attributes allow the procedure to specify to which argument, if any, theinvoking object is passed. For example, pass(x) passes it to dummy argument x, whilenopass indicates not to pass it at all.‣ NON_OVERRIDABLE attribute specifies that the type-bound procedure cannot beoverridden during type extension.‣ PRIVATE and PUBLIC attributes determine where the type-bound procedures can bereferenced. <strong>The</strong> default is public, which allows the procedures to be referenced anywherein the program having that type of variable. If the procedure is private, it can only bereferenced from within the module in which it is defined.‣ DEFERRED are type bound procedures that are declared in an abstract type, as describedin Abstract Types and Deferred Bindings, and must be defined in all of its non-abstract typeextensions.<strong>The</strong> procedure-name option is the name of the underlying procedure that implements thetype-bound procedure. This option is required if the name of the underlying procedure differs<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 126

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

Saved successfully!

Ooh no, something went wrong!