Gemäß der Norm ist es nicht erlaubt. Das Komponente Attribut Spezifizierer kann nur pointer
und dimension
für Fortran 90/95 (Abschnitt 4.4.1), zusätzlich allocatable
in Fortran 2003 (Abschnitt 4.5.3) und zusätzlich codimension
und contiguous
für Fortran 2008 (Abschnitt 4.5. 4.1).
Sie können die Dokumente here erhalten.
Ich stieß auf ein ähnliches Problem mit dem target
Spezifizierer, der auch nicht erlaubt ist.
EDIT: Warum nicht versuchen private
Komponenten?
module typedef
type :: my_type
integer, private :: a_int = 1
real(kind(1.d0)) :: b
contains
procedure :: a
end type my_type
contains
function a(complex_type)
class(my_type),intent(in) :: complex_type
integer :: a
a = complex_type%a_int
end function
end module
program my_prog
use typedef
implicit none
type (my_type) :: complex_type
complex_type%b = 2.d0 ! This should work
write(*,*) complex_type%a(), complex_type%b
! complex_type%a_int = 3 ! This should fail
end program my_prog
* ... wie kann ich sicherstellen, dass 'a' an keiner anderen Stelle geändert wird? * Sie meinen, es nicht zu benutzen? : D –
In Fortran 2003 gibt es viele andere Möglichkeiten. Es kann eine private Variable mit Setter/Getter-Methoden sein. Es kann eine geschützte Komponente sein ... –