Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oop Fortran派生类型继承_Oop_Fortran_Derived Types - Fatal编程技术网

Oop Fortran派生类型继承

Oop Fortran派生类型继承,oop,fortran,derived-types,Oop,Fortran,Derived Types,假设我有一个派生类型bar\u a,它作为变量bar包含在派生类型foo\u a中 现在我想扩展bar\u a并创建一个名为bar\u b的新派生类型。我尝试了以下方法: program main implicit none ! Base types ----------- type :: bar_a integer :: a end type bar_a type :: foo_a type(bar_a) :: bar end type f

假设我有一个派生类型
bar\u a
,它作为变量
bar
包含在派生类型
foo\u a

现在我想扩展
bar\u a
并创建一个名为
bar\u b
的新派生类型。我尝试了以下方法:

program main
  implicit none

  ! Base types -----------
  
  type :: bar_a
    integer :: a
  end type bar_a
  
  type :: foo_a
    type(bar_a) :: bar
  end type foo_a
  
  ! Extended types -------
  
  type, extends(bar_a) :: bar_b
    integer :: b
  end type bar_b
  
  type, extends(foo_a) :: foo_b
    type(bar_b) :: bar ! <-- Component ‘bar’ at (1) already in the parent type
  end type foo_b
  
  ! ----------------------

  type(foo_b) :: foo

  print *, foo%bar%a
  print *, foo%bar%b

end program main
主程序
隐式无
! 基本类型-----------
类型::bar_a
整数::a
端型杆
类型::foo_a
类型(bar_a)::bar
端部类型foo_a
! 扩展类型-------
类型,扩展(条形图a)::条形图b
整数::b
端型杆
类型,扩展(foo_a)::foo_b

类型(bar_b)::bar 当我尝试编译时,我得到了一个更好的消息:

aa.f90:21:22:

   10 |   type :: foo_a
      |               2
......
   21 |     type(bar_b) :: bar ! <-- Component ‘bar’ already in the parent type
      |                      1
Error: Component ‘bar’ at (1) already in the parent type at (2)
aa.f90:21:22:
10 |类型::foo|u a
|               2
......

21 |类型(bar|b)::bar!有没有办法“覆盖”声明?在我的情况下,我想将
foo_a
中的类型绑定过程“转移”到
foo_b
。这是一个不同的问题,您应该在您的问题(编辑当前问题或提出新问题)中说明这一点,我的回答是基于所问的内容。对不起。我用笨拙的措词回答了这个问题。我把问题编辑得更清楚了。