My IDE is: Code::Blocks 20.03 ( MinGW 9.2.0 )
This is my code:
module mod_kompleks
use, intrinsic :: iso_c_binding, only : rp => c_double
implicit none
type, public :: kom_bro
real(rp), private :: rea
real(rp), private :: img
contains
procedure, pass(kdt), private :: kom_bro_ini
procedure, pass(kdt), public :: uzm_rea => uzm_pod_rea
procedure, pass(kdt), public :: uzm_img => uzm_pod_img
procedure, pass(kdt), private :: kom_bro_sab
generic, public :: operator(+) => kom_bro_sab
end type kom_bro
interface kom_bro
module procedure kom_bro_kon
end interface kom_bro
private :: kom_bro_kon
contains
function kom_bro_kon( bro_rea, bro_img ) result( bro )
real(rp), intent(in) :: bro_rea
real(rp), intent(in) :: bro_img
type(kom_bro) :: bro
call bro%kom_bro_ini(bro_rea, bro_img)
end function kom_bro_kon
subroutine kom_bro_ini(kdt, dio_rea, dio_img)
class(kom_bro), intent(out) :: kdt
real(rp), intent(in) :: dio_rea
real(rp), intent(in) :: dio_img
kdt%rea = dio_rea
kdt%img = dio_img
end subroutine kom_bro_ini
function uzm_pod_rea( kdt ) result( rez )
class(kom_bro), intent(in) :: kdt
real(rp) :: rez
rez = kdt%rea
end function uzm_pod_rea
function uzm_pod_img( kdt ) result( rez )
class(kom_bro), intent(in) :: kdt
real(rp) :: rez
rez = kdt%img
end function uzm_pod_img
function kom_bro_sab( kdt, bro ) result( rez )
class(kom_bro), intent(in) :: kdt
class(kom_bro), intent(in) :: bro
type(kom_bro) :: rez
rez%rea = kdt%rea + bro%rea
rez%img = kdt%img + bro%img
end function kom_bro_sab
end module mod_kompleks
program kompleksni_broj
use, non_intrinsic :: mod_kompleks
implicit none
type(kom_bro) :: broj_01, broj_02, broj_03
broj_01 = kom_bro(1.1_rp,2.2_rp)
print '(1x,f4.2,1x,"j",1xf4.2)', broj_01%uzm_rea(), broj_01%uzm_img()
broj_02 = kom_bro(3.3_rp,4.4_rp)
print '(1x,f4.2,1x,"j",1xf4.2)', broj_02%uzm_rea(), broj_02%uzm_img()
broj_03 = broj_01 + broj_02
print '(1x,f4.2,1x,"j",1xf4.2)', broj_03%uzm_rea(), broj_03%uzm_img()
end program kompleksni_broj
My intention is to disable access to the kom_bro_sab
procedure outside the mod_kompleks
module. In case I want to construct a complex number with values for the real and imaginary part in the main program, after typing the word kom I get the opportunity to choose the procedure kon_bro
, which of course I wanted, but next to that function I am offered the opportunity to choose the procedure kom_bro_sab
. How can I prevent this (I want only the procedure kom_bro_sab
and the operator +
to be visible)?
I will add screenshot of what i got even the type - bound procedure was private:
question from:
https://stackoverflow.com/questions/65602970/generic-interfaces-and-operator-overloading-how-to-set-procedure-from-generic