- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'ld like to ask why it isn't possible to use a base class for passing the object:
module greet_mod type, abstract :: GREETER character(100) :: name contains procedure(greet_fun), deferred :: greet end type GREETER abstract interface subroutine greet_fun(this) import :: GREETER class(GREETER), intent(in) :: this end subroutine greet_fun end interface type, extends(GREETER) :: ENGLISH_GREETER contains procedure greet => en_greet end type ENGLISH_GREETER contains subroutine en_greet(this) class(GREETER), intent(in) :: this !won't work !class(ENGLISH_GREETER), intent(in), this !works write(*,*) 'Hi ',trim(adjustl(this%name)) end subroutine en_greet end module greet_mod program test_greeter use greet_mod class(GREETER), allocatable :: gtr allocate(ENGLISH_GREETER::gtr) gtr%name='F03' call gtr%greet() end program test_greeter
error #8262: For a type-bound procedure that has the PASS binding attribute, the first dummy argument must have the same declared type as the type being defined. [THIS] subroutine en_greet(this) ----------------------^
Is this normal behavior?
Thanks in advance!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this is what the standard specifies.
C456 The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object with the same declared type as the type being defined; all of its length type parameters shall be assumed; it shall be polymorphic (4.3.1.3) if and only if the type being defined is extensible (4.5.7). It shall not have the VALUE attribute.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page