<Syntax> |
|
|
|
An object-bound procedure is a procedure pointer component, declared in the component definition part of a derived type definition:
proc-component-def-stmt ::= PROCEDURE ( [ interface ] ) , proc-component-attr-list :: proc-component-decl-list
interface ::= interface-name | type
An interface-name is the name of an abstract interface or of any procedure with an explicit interface (e.g. a module procedure); the name cannot be the same as an intrinsic type name (e.g. LOGICAL).
For the syntax of type see the type declaration statement.
proc-component-attr-list ::= proc-component-attr [ , proc-component-attr ]...
proc-component-attr | ::= | NOPASS |
| | | PASS [ ( dummy-arg-name ) ] |
| | | POINTER |
| | | PRIVATE |
| | | PUBLIC |
The PUBLIC and PRIVATE attributes are only permitted in the specification part of a module.
The POINTER attribute is required.
proc-component-decl-list ::= proc-component-decl [ , proc-component-decl ]...
proc-component-decl ::= proc-component-name [ =>NULL() ]
The syntax for invoking an object-bound procedure is as follows:
object-name % proc-component-name [ ( [ actual-arg-list ] ) ]
This syntax may appear in a CALL statement or as a function reference; as a function reference, the parentheses are required (and no alternate return specifier is permitted). The syntax of the actual-arg-list is described under the CALL statement.
|
|
|
|
|
|
<Semantics> |
|
|
|
The procedure component definition statement declares one or more object-bound procedures (i.e. procedure pointer components) of a derived type.
If a proc-component-decl contains “=> NULL()”, the procedure pointer component is default initialised to null.
Default initialisation is applied whenever an object of the type is created, and for INTENT(OUT) arguments.
An object-bound procedure may be explicitly declared to be PUBLIC or PRIVATE; otherwise, it is PRIVATE if the component definition statements are preceded by a PRIVATE statement, and PUBLIC otherwise.
A PRIVATE component cannot be accessed from outside the module that defines the type.
The object-bound procedure is determined by association with an actual procedure by pointer assignment (this may be either by a pointer assignment statement or implicitly in a structure constructor).
When it is invoked, the invoking object is normally passed automatically to the procedure as an argument according to the PASS attribute; any supplied argument list provides values for the other arguments.
The object-bound procedure is thus similar to a type-bound procedure in how the PASS attribute works, but the determination of the actual procedure to invoke depends on the pointer association of the component (for object-bound procedures) whereas for type-bound procedures it depends only on the dynamic type of the object.
|
|
|
|
|
|
<Related> |
|
|
|
CALL statement,
Component definition statement,
Derived Type Definition,
NOPASS attribute,
PASS attribute,
POINTER attribute,
PRIVATE attribute,
PUBLIC attribute,
TYPE statement,
Type declaration statement,
Type-bound procedure |
|
|