Demo entry 6782249

fortran operator overloading

   

Submitted by drigomen on Jan 12, 2019 at 00:48
Language: Fortran. Code size: 662 Bytes.

module type_test
  implicit none

  character(len=*), parameter :: text = 'some modern Fortran operator'

  type :: type_test_try
    private
    real :: h = 1.0
  end type
  ! (...)
  interface operator(+)
    module procedure :: real_plus_test, test_plus_real
  end interface

contains
  pure real function real_plus_test(left, right)
    real, intent(in) :: left
    type(type_test_try), intent(in) :: right
    real_plus_test = left + right%h
  end
  pure real function test_plus_real(left, right)
    type(type_test_try), intent(in) :: left
    real, intent(in) :: right
    test_plus_real = left%h + right
  end
! (...)
end module

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).