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 ProgrammingUsing the example above, we can invoke initialize with a shape, rectangle, or square object:type(shape) :: shp! declare an instance of shapetype(rectangle) :: rect! declare an instance of rectangletype(square) :: sq! declare an instance of squarecall shp%initialize(1, .true., 10, 20) ! initialize shapecall rect%initialize(2, .false., 100, 200, 50, 25) ! initialize rectanglecall sq%initialize(3, .false., 400, 500, 30, 20) ! initialize rectangle7.2.7. Procedure OverridingMost OOP languages allow a child object to override a procedure inherited from its parent object.This is known as procedure overriding. In F2003, you can specify a type-bound procedure in achild type that has the same binding-name as a type-bound procedure in the parent type. Whenthe child overrides a particular type-bound procedure, the version defined in its derived type isinvoked instead of the version defined in the parent. In the following example, rectangledefines an initialize type-bound procedure that overrides shape's initialize type-boundprocedure.<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 130

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

Saved successfully!

Ooh no, something went wrong!