- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Procedure pointers, when used as derived type components, are type-bound by default ---i.e., an instance of the derived type is passed as the first argument, and is referred to as the passed-object.
The error is telling you that the first argument in the abstract interface should be of CLASS(operator_type). To override the default behavior, you can use PASS (to confirm or state which argument is the passed-object) or NOPASS (in which case no instance of the derived type is passed).
Although it might not apply in your case, one alternative to procedure pointer components is a deferred type-bound procedure; for that, you must add ABSTRACT to the derived type definition. Unlike the procedure pointer component, a deferred type-bound procedure has the advantage that it cannot be neglected (i.e., whomever uses your derived type, must extend it and override the procedure), so you can actually invoke it from other type-bound procedures of the abstract type. The ABSTRACT attribute is not allowed for recursive derived types, though.
One example:
[fortran]module operator_class type :: data_type real, allocatable :: values(:) integer :: n_values end type data_type type, abstract :: operator_type type(data_type), pointer :: data1 => null() type(data_type), pointer :: data2 => null() type(data_type), pointer :: result => null() contains procedure(operation_type), nopass, deferred :: operation end type abstract interface subroutine operation_type( data1, data2, result ) import type(data_type), target, intent(inout) :: data1 type(data_type), target, intent(inout) :: data2 type(data_type), pointer :: result end subroutine end interface end module operator_class module operator_class_implementation use operator_class type, extends(operator_type) :: operator_type_impl type(operator_type_impl), pointer :: operator1 => null() type(operator_type_impl), pointer :: operator2 => null() contains procedure, nopass :: operation end type contains subroutine operation( data1, data2, result ) type(data_type), target, intent(inout) :: data1 type(data_type), target, intent(inout) :: data2 type(data_type), pointer :: result !... end subroutine end module operator_class_implementation[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page