Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

can i delete some procedures from the generic binding list which inherits from the superclass

Li_L_
New Contributor I
313 Views

it seems a quite simple question but i can't find an explicit answer...

someone knows that? how to do it?

0 Kudos
1 Solution
IanH
Honored Contributor II
313 Views

If type `sub` is an extension of super, then it is supposed to be able to be treated as an object of type `super`.  An object of type `super` has a accessible generic binding that has the characteristics of the `f2` specific binding, so an object of type `sub` is also required to have such an accessible binding.  The language rules enforce this.

Remember that if the parent type of an object is accessible and not abstract, you can always access the object as if it was of the parent type by using the parent component `s%super`.  Even if the parent type is abstract you can also pass an object of type `sub` to a procedure that takes a polymorphic argument of type `super`, so the ability to hide a particular specific binding from a generic for references via an object of the declared type of `sub` would be pretty "weak".

Perhaps you need a different type hierarchy - perhaps `sub` is not an extension of super, but both `sub` and `super` are extensions of some third type that does not have the specific binding that you want to remove.

An impure elemental procedure can contain a stop statement.


 

View solution in original post

0 Kudos
4 Replies
FortranFan
Honored Contributor II
313 Views

More informed readers of the standard can give you a better answer, but see this thread:

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/681705

Those procedures bound to the superclass on the generic list that have the PRIVATE attribute seem to be inaccessible outside the module containing the superclass, if I understand the Fortran 2008 interp 052 correctly.  So making use of the PRIVATE attribute in conjunction with placing the inherited class is another module might give you what you're looking for.

I don't know but other than  the above possibility, it appears one can only OVERRIDE.

0 Kudos
Li_L_
New Contributor I
313 Views

FortranFan wrote:

More informed readers of the standard can give you a better answer, but see this thread:

https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux...

Those procedures bound to the superclass on the generic list that have the PRIVATE attribute seem to be inaccessible outside the module containing the superclass, if I understand the Fortran 2008 interp 052 correctly.  So making use of the PRIVATE attribute in conjunction with placing the inherited class is another module might give you what you're looking for.

I don't know but other than  the above possibility, it appears one can only OVERRIDE.

i tried, but i failed

 

module super_
implicit none
    private
    public::    super
!---
    type:: super
    
    contains
        generic::           g   => f1,f2
        procedure::         f1
        procedure,private:: f2
    end type super
contains
    function f1(this)
    class(super):: this
    integer(4)::    f1
        f1 = 1
    end function f1
    
    function f2(this,a)
    class(super):: this
    integer(4)::    f2,a
        f2 = 2
    end function f2
end module super_

module sub_
use super_
implicit none
    type,extends(super):: sub
    contains
    end type sub
contains
end module sub_
    
program test
use sub_
implicit none
type(sub):: s

    print*, s%g()
    print*, s%g(2)
    print*, s%f1()
    !print*, s%f2()

end program

private attr just prevent the use of f2 directly , but i access f2 with the generic procedure

actually i tried disable the f2 in subclass by overloading. but i can't write a 'stop' statement when i want f2 be an elemental procedure

so another question, how can i disable f2 efficiently without losing the elemental attr

0 Kudos
IanH
Honored Contributor II
314 Views

If type `sub` is an extension of super, then it is supposed to be able to be treated as an object of type `super`.  An object of type `super` has a accessible generic binding that has the characteristics of the `f2` specific binding, so an object of type `sub` is also required to have such an accessible binding.  The language rules enforce this.

Remember that if the parent type of an object is accessible and not abstract, you can always access the object as if it was of the parent type by using the parent component `s%super`.  Even if the parent type is abstract you can also pass an object of type `sub` to a procedure that takes a polymorphic argument of type `super`, so the ability to hide a particular specific binding from a generic for references via an object of the declared type of `sub` would be pretty "weak".

Perhaps you need a different type hierarchy - perhaps `sub` is not an extension of super, but both `sub` and `super` are extensions of some third type that does not have the specific binding that you want to remove.

An impure elemental procedure can contain a stop statement.


 

0 Kudos
Li_L_
New Contributor I
313 Views

ianh wrote:

If type `sub` is an extension of super, then it is supposed to be able to be treated as an object of type `super`.  An object of type `super` has a accessible generic binding that has the characteristics of the `f2` specific binding, so an object of type `sub` is also required to have such an accessible binding.  The language rules enforce this.

Remember that if the parent type of an object is accessible and not abstract, you can always access the object as if it was of the parent type by using the parent component `s%super`.  Even if the parent type is abstract you can also pass an object of type `sub` to a procedure that takes a polymorphic argument of type `super`, so the ability to hide a particular specific binding from a generic for references via an object of the declared type of `sub` would be pretty "weak".

Perhaps you need a different type hierarchy - perhaps `sub` is not an extension of super, but both `sub` and `super` are extensions of some third type that does not have the specific binding that you want to remove.

An impure elemental procedure can contain a stop statement.

 

that's the exact answer i want. thanks!

0 Kudos
Reply