Quantcast
Channel: Fortran
Viewing all articles
Browse latest Browse all 3108

Assignment overloading for intrinsic types?

$
0
0

Consider the following toy example:

module test_module

  implicit none

  type :: myint

    integer :: i = 0

    contains

    generic :: assignment(=) => int_to_myint
    procedure :: int_to_myint

  end type myint

contains

  subroutine int_to_myint(me,i)  !myint = integer assignment

  implicit none

  class(myint),intent(inout) :: me
  integer,intent(in)         :: i

  me%i = i

  end subroutine int_to_myint

end module test_module

The type(myint)=integer assignment works great.  My question is this: is it possible to have the reverse assignment (integer=type(myint)) work as well?  This would be like overloading the assignment operator for the integer type, I guess?  Is such a thing possible?


Viewing all articles
Browse latest Browse all 3108

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>