Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

How have self reffering to child class in deffered precedure interface of an abstract class

Say we have a parent abstract class:

module class_absParent
public :: absParent

      type, abstract :: absParent
      contains
          procedure(interface_func1), public, deferred :: func1
      end type
     
      abstract interface 
          function interface_func1(self) result(dblResult) 
              import :: absMaterial
!! I want self be the child class not absParent, is it okay to use absMaterial in this line?
              class(absMaterial), intent(inout) :: self 
              real*8 :: dblResult
          end function
      end interface 
...

 

And the func1 in the child class needs to access the properties of child class so I want self to refer to the child class and not the parent abstract class.

 

module class_child
use class_absParent
implicit none
public :: child
type, extends(absParent) :: child
...
function mat02_yield1(self) result(dblResult)
!! does this contradicts the interface in parent class?
    class(child), intent(inout) :: self 
...
end function

...

 

I am getting error

The dummy arguments of an overriding and overridden binding that correspond by position must have the same characteristics, except for the type of the passed object dummy arguments.

 

0 Kudos
1 Reply
Highlighted
Beginner

self can be an object of

self can be an object of child class since "type of the passed object dummy arguments" can be different objects,

Error was caused since intent statement in Parent and Child classes were different.

Also related to this topic:

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/280171

0 Kudos