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

accessibility of TYPE components with PRIVATE attribute

yamajun2
Beginner
388 Views
I am a bit puzzled with the accessibility of derived type components with PRIVATE attribute.
In the program below,
  1. when PRIVATE attribute is set as a statement, I got compile errors even for the access from subroutines inside the module. ("error #6292: The parent type of this field is use associated with the PRIVATE fields attribute [30.0]")
  2. While adding PRIVATE attribute as an option to REAL statement, I get no error but then I can access to the component variables by assignment. (t = t_test(10.0, 20.0))
I have two questions;
  1. Is there any difference between the two ways of setting accessibility attribute?
  2. Is the assignment by structure constructor allowed for PRIVATE components?
Thanks in advance!
[bash]MODULE m_type
    IMPLICIT NONE
    PRIVATE
    PUBLIC :: t_test
    
    TYPE :: t_test
!       PRIVATE
!       REAL :: x, y
       REAL, PRIVATE :: x, y
     CONTAINS
       PROCEDURE, PUBLIC :: pr
       PROCEDURE, PUBLIC :: set
    END TYPE t_test
  
  CONTAINS
  
    SUBROUTINE pr(this)
      CLASS(t_test), INTENT(IN) :: this
      PRINT *, this%x, this%y
      RETURN
    END SUBROUTINE pr
    
    SUBROUTINE set(this, that)
      CLASS(t_test), INTENT(OUT) :: this
      TYPE (t_test), INTENT(IN ) :: that
      this%x = that%x
      this%y = that%y
      RETURN
    END SUBROUTINE set

END MODULE m_type


PROGRAM test
    USE m_type
    IMPLICIT NONE
    TYPE (t_test) :: t
    t = t_test(10.0, 20.0)
    CALL t%pr()     
    CALL t%set( t_test(30.0, 40.0) )
    CALL t%pr()     
    
    
    STOP
END PROGRAM test[/bash]
0 Kudos
0 Replies
Reply