Question

After searching, I was able to find one question regarding the same error I just encountered, but for different reasons here (they weren't familiar with pass... different issue).

My question is simple. In Fortran, can a function expecting an argument of type class(parent) accept instead class(derived_from_parent)?

If an example or clarification is needed, please ask. Many thanks.

Was it helpful?

Solution

Yes, that works without any problem. If you need to use any property of the extended (derived) type, you have to use select type, but if not, it is without any complication.

If you need the dummy argument to be allocatable or pointer, there are some restrictions:

12.5.2.5

2 The actual argument shall be polymorphic if and only if the associated dummy argument is polymorphic, and either both the actual and dummy arguments shall be unlimited polymorphic, or the declared type of the actual argument shall be the same as the declared type of the dummy argument.

(the reason for this is explained in NOTE 12.27 in ISO/IEC 1539-1:2010)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top