PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

inheritance and type-bound procedures

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
rmpalmer



Joined: 13 Jul 2011
Posts: 4

PostPosted: Thu Dec 29, 2011 8:29 am    Post subject: inheritance and type-bound procedures Reply with quote

I have two simple source files, one.f90 (compiles ok) and two.f90.
and two.f90. the latter fails to compile with error 0155 (interface is not compatible with parent's interface for type bound procedure comparePoint). Can you help me spot what is wrong?

thanks - Rick

module one
type, abstract, public :: comparable
!
contains
procedure(boolean_binary) :: compareTo
!
end type comparable

abstract interface
!
logical function boolean_binary(this, other)
import :: comparable
class(comparable), intent(in) :: this
class(comparable), intent(in) :: other
end function boolean_binary
!
end interface

end module one

*************************************************
module two

use one

type, public, extends(comparable) :: point
contains
procedure :: compareTo => comparePoint
end type point

contains

logical function comparePoint(this, other)
class(point), intent(in) :: this
class(point), intent(in) :: other
comparePoint = .true.
end function comparePoint

end module two
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6639
Location: The Portland Group Inc.

PostPosted: Tue Jan 03, 2012 5:05 pm    Post subject: Reply with quote

Hi Rick,

The interface for comparePoint in module two is not compatible with the parent interface in module one. The second argument in comparePoint must be the same as the parent's second argument. In general, the arguments for a child type bound procedure must match the parent's, except for the passed object argument (in which case, the passed object argument must be the same as the type defining the type bound procedure).

To correct the error, you should change the second argument in comparePoint from:
Code:
class(point), intent(in) :: other

to
Code:
class(comparable), intent(in) :: other


Also you need to add the "deferred" attribute on the parent compareTo (deferred must appear if an interface is used in a type bound procedure definition).

For example.
Code:
procedure(boolean_binary), deferred :: compareTo


Our compiler should have reported an error on that as well, but didn't. We will investigate that.

Below is the complete corrected code:

Code:
module one
type, abstract, public :: comparable
!
contains
procedure(boolean_binary),deferred :: compareTo
!
end type comparable

abstract interface
!
logical function boolean_binary(this, other)
import :: comparable
class(comparable), intent(in) :: this
class(comparable), intent(in) :: other
end function boolean_binary
!
end interface

end module one


module two

use one

type, public, extends(comparable) :: point
contains
procedure :: compareTo => comparePoint
end type point

contains

logical function comparePoint(this, other)
class(point), intent(in) :: this
class(comparable), intent(in) :: other
comparePoint = .true.
end function comparePoint

end module two



- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group