2
이전 및 새로운 포트란 코드에 문제가 있습니다. 새로운 부분은 객체 지향적이며 이전 부분은 함수 포인터와 함께 작동합니다.포트란 : 추상 멤버 함수 포인터 function
내 문제는, 그 함수가이 특별한 객체와 함께 작동하도록 함수 포인터에 멤버 함수를 할당하고 싶습니다.
error #8191: The procedure target must be a procedure or a procedure pointer.
이 문제를 극복 할 수있는 가능성이 :
module test
! abstract class
type, abstract :: base
contains
procedure (doSth), deferred :: doSomething
end type base
! deferred function
abstract interface
subroutine doSth(this)
import :: base
class(base) :: this
end subroutine
end interface
! derived class
type, extends(base) :: child
contains
procedure :: doSomething => do_Sth
end type child
contains
! deferred function implemented by child
subroutine do_Sth(this)
class(child) :: this
! ...
! ...
end subroutine
! function pointer to member function
subroutine get_functionPointer()
procedure() , pointer :: funcPtr
type (child), pointer :: childPtr
allocate (childPtr)
funcPtr => childPtr%doSomething
! ... This does not work
end subroutine
end module
이 나에게 오류 메시지를 제공합니다 : 여기에 같은 오류가있는 예제 코드는?
:
:
! function pointer to member function
subroutine get_functionPointer()
procedure(doSth), pointer :: funcPtr
type (child), pointer :: childPtr
allocate (childPtr)
call funcPtr(childPtr)
end subroutine
:
:
도와 주셔서 감사합니다 많은 : 약간의 도움으로
Fortran에는 멤버 함수 개념이 없습니다. 포인터에 funcPtr에 할당하려고하는 것은 바인딩입니다. 오른쪽에 대한 관련 프로 시저의 이름은'do_Sth'입니다. 아마도 [this] (http://stackoverflow.com/questions/11318816/passing-type-bound-procedures-as-arguments-in-fortran-90)에 대한 허용 된 대답을 읽으십시오. 대신 프로 시저 포인터를 할당하는 동안 논쟁 관계를 맺을 때도 비슷한 규칙이 적용됩니다. – IanH