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

Some problem about Type-Bound-Procedure

asymptotic
Beginner
403 Views

I have a problem about Type-Bound-Procedure, can you help me? Thanks a lot.

Win7 (64-bit) + Visual Studio 2008 + Intel fortran 11.1.067

---- source code ------

Module GenericIntrinsicFunction

implicit none

type, public:: Rational

integer:: Num ! numerator

integer:: Den ! Denominator

contains

! The passed-object dummy argument must be a polymorphic

! dummy data object if the type being defined is extensible. [RAT_IN]

procedure:: abs => RationalAbs ! error

end type

interface Abs

module procedure RationalAbs

end interface

contains

function RationalAbs(Rat_in) result(Rat_out)

implicit none

type(Rational), intent(in):: Rat_in

type(Rational):: Rat_out

integer, intrinsic:: abs

Rat_out % Num = abs(Rat_in % Num)

Rat_out % Den = abs(Rat_in % Den)

return

end function

End Module

0 Kudos
1 Reply
thomas_boehme
New Contributor II
403 Views

Hi asymptotic,

as the error message says, the passed object dummy argument must be polymorphic, i.e. you have to use CLASS(Rational) instead of TYPE(Rational) in your function definition for the Rat_in argument.

Your function header should look like this:

function RationalAbs(Rat_in) result(Rat_out)

implicit none

class(Rational), intent(in):: Rat_in

type(Rational):: Rat_out

best regards,

Thomas

0 Kudos
Reply