【发布时间】:2018-04-29 20:55:00
【问题描述】:
现代 Fortran(90、2003 甚至 2008)是否有可能拥有一个自定义类型,默认情况下会访问其中一个属性:
program test
use iso_fortran_env
type MYTYPE_t
real(real64) :: data
end type MYTYPE_t
type(MYTYPE_T) :: test
real(real64) :: foo
! This works
test%data = 5.0
! Is there a way to be able things like this:
test = 5.0
print*, sqrt(test)
foo = test + 3
end program
【问题讨论】:
-
定义的分配是否满足您的要求?
-
它以某种方式完成了这项工作。但问题是,必须覆盖所有默认运算符,并且它不适用于 fortran 内在函数。
-
它会起作用的,看我的回答。
标签: fortran fortran2003 custom-type fortran2008