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

Is an allocatable of polymorphic variables polymorphic?

E___Sebastian
Beginner
605 Views

In our code we sometimes need to iterate over a list of polymorphic variables. To do that we create a derived type as a container such as:

type myContainerT
  class(myExtendedBaseType), allocatable :: var
end type myContainerT

Now, myContainerT will not be extended, but var is polymorphic.
The question is, whether myContainerT is polymorphic too because it has polymorphic member variables and thus should be declared with class instead of type e.g. in dummy argument lists.

Even though the ifort seems to not care about that, any explanation of what goes on in the background would be greatly appreciated.

Thanks!

0 Kudos
1 Solution
FortranFan
Honored Contributor II
584 Views

@E___Sebastian ,

No, the objects and dummy argument references to this 'container' type need not be declared as 'CLASS', they can be 'TYPE'.

In fact, programs should be very judicious in their use of the polymorphic option with 'CLASS' and only make use of it when it serves a valuable purpose with respect to program design and logic.

View solution in original post

1 Reply
FortranFan
Honored Contributor II
585 Views

@E___Sebastian ,

No, the objects and dummy argument references to this 'container' type need not be declared as 'CLASS', they can be 'TYPE'.

In fact, programs should be very judicious in their use of the polymorphic option with 'CLASS' and only make use of it when it serves a valuable purpose with respect to program design and logic.

Reply