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_Intel Fortran - Fatal编程技术网

Oop Fortran中两种不同声明之间的差异

Oop Fortran中两种不同声明之间的差异,oop,fortran,intel-fortran,Oop,Fortran,Intel Fortran,我有以下建议: type t_octree real :: box(2,3) type(t_octree), pointer :: parent => NULL() type(t_octree), pointer :: children(:) => NULL() contains final :: D

我有以下建议:

  type t_octree
     real                          :: box(2,3)
     type(t_octree), pointer       :: parent      => NULL()
     type(t_octree), pointer       :: children(:) => NULL()
     contains
     final                         :: DESTROY_OCTREE
  end type t_octree


  interface t_octree
     module procedure              :: INIT_OCTREE
  end interface t_octree
现在,我的构造函数或解构师:

  subroutine INIT_OCTREE( this, num_points, box )

  implicit none

  class(t_octree)      :: this
  integer                :: num_points
  real                   :: box(2,3)
        (...)
  end subroutine INIT_OCTREE

  subroutine DESTROY_OCTREE( this )

  implicit none
  type(t_octree)         :: this
    (....)
  end subroutine DESTROY_OCTREE
有人能解释一下为什么两者都起作用吗,例如,如果我用
类型(t_八叉树)::this
类(t_八叉树)::this
。 我汇编了这两个案例,它们都奏效了。那么这里的具体区别是什么呢


我们什么时候应该使用哪个?

这是一个非常重要的区别,以前肯定已经讨论过了。你知道多态性是什么吗?如果你想问一些比这两个链接提供的内容更具体的问题,只需编辑你的问题,它就可以重新打开。是的,我知道这一点,也知道一般OOP。关于重复问题。我已经看了这个问题,但它没有清楚地说明我的示例中所示的两个声明之间的区别。由于这两种方法都有效,所以很高兴知道为什么或/和它们之间的差异,但也知道这些差异的一般性。这是非常具体的,不是吗?我展示了两种方法来声明对象
t_octree
,这两个例子都有效,那么它们之间的区别是什么呢?类是多态的,这意味着子例程也可以使用从类型(子类型)派生的类型来调用。基本上就是这样。