Oop 选择类型:不能调用仅在派生类型中定义的子例程?
我最近开始使用Fortran深入研究OOP。我有一个类型层次结构,其中我有一个抽象的基本类型genericProblem和一个派生类型specificProblemspecificProblem有一个未在genericProblem中定义的子例程,在我的示例中称为“InitializeWith” 似乎我误解了select类型构造。我认为它是专门为这样的情况而设计的,我知道我可以期望变量问题属于某种类型的泛型问题,编译器应该知道“我显然属于特定问题类型,现在特定于该类型的函数调用是可以的” 然而,我得到了一份工作 这不是在包含结构中定义的字段名。 错误与下面的例子,所以我可能错过了一些东西。有人能给我指出正确的方向吗Oop 选择类型:不能调用仅在派生类型中定义的子例程?,oop,fortran,derived-types,Oop,Fortran,Derived Types,我最近开始使用Fortran深入研究OOP。我有一个类型层次结构,其中我有一个抽象的基本类型genericProblem和一个派生类型specificProblemspecificProblem有一个未在genericProblem中定义的子例程,在我的示例中称为“InitializeWith” 似乎我误解了select类型构造。我认为它是专门为这样的情况而设计的,我知道我可以期望变量问题属于某种类型的泛型问题,编译器应该知道“我显然属于特定问题类型,现在特定于该类型的函数调用是可以的” 然而,
subroutine AssignSomething(problem,rhsTarget)
class(genericProblemT), intent(in out) :: problem
class(genericProblemT), target, intent(in) :: rhsTarget
select type (lhsProblem => problem)
type is (specificProblemT)
! Try setting up the rhsProblem:
call lhsProblem%InitializeWith(rhsTarget) ! Gives an error
class default
! give error for unexpected/unsupported type
throw some error
end select
end subroutine AssignSomething
请显示派生类型的详细信息。更好的是,提供一个。