Type detection: Difference between revisions

Line 567:
=={{header|Fortran}}==
 
Fortran 2008 and later can do this with general types, using ‘classthe unlimited polymorphic class ''class(*)''.
 
Polymorphism involving types derived from a base type can be done in Fortran 2003 and later.
 
There is also, in modern Fortran, an overload mechanism that can be used to give procedures that take different types the same name, but I presume the task is for run-time type polymorphism rather than for templates or overloads.
 
Legacy versions of Fortran have ways to store data of one type in a variable declared as some other type, and this mechanism could be employed.
Below I use ‘class(*)’, which seems best to satisfy the task description. The ‘print_text’ subroutine is used to print a string, an array of strings, and an input file.
 
===Unlimited type polymorphism===
Below I use ‘class(*)’, which seems best to satisfy the task description. The ‘print_text’ subroutine is used to print a string, an array of strings, and an input file.
 
<lang fortran>program input_type_detection_demo
1,448

edits