- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, the following code produces an error with ifort 2018u2 on x64 platform:
module test1 implicit none type, abstract :: tp1 private contains private procedure(iequals), public, pass, deferred :: equals end type tp1 abstract interface function iequals(this, obj) import tp1 logical :: iequals class(tp1), intent(in) :: this class(tp1), intent(in) :: obj end function iequals end interface end module test1 module test2 use test1, only: tp1 implicit none type, extends(tp1) :: tp2 private integer :: var2 contains private procedure, public, pass :: equals => equalsfunc end type tp2 contains function equalsfunc(this, obj) implicit none logical :: equalsfunc class(tp2), intent(in) :: this class(tp1), intent(in) :: obj select type(obj) type is(tp2) equalsfunc = (this % var2 == obj % var2) class default equalsfunc = .false. end select end function equalsfunc end module test2 module test3 use test1, only: tp1 use test2, only: tp2 implicit none type, extends(tp1) :: tp3 private type(tp2) :: var3 contains private procedure, public, pass :: equals => equalsfunc end type tp3 contains function equalsfunc(this, obj) implicit none logical :: equalsfunc class(tp3), intent(in) :: this class(tp1), intent(in) :: obj select type(obj) type is(tp3) equalsfunc = (this % var3 == obj % var3) class default equalsfunc = .false. end select end function equalsfunc end module test3
Error message is:
error #6355: This binary operation is invalid for this data type. [VAR3]
on line 78. Is this a bug and is there any workaround that I can temporarily make it through ? Thanks for any help.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no generic binding specification for ASSIGNMENT(=) in the code as shown. The error message makes sense if this is really the case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hate disagreeing with Ian (it's almost as bad as disagreeing with Steve) but I think the problem is that there is no defined operator "==" specified for something of type TP2.
the line in question is asking "is this%var3 the same as obj%var3" but there is nothing to define what "the same" means between two objects of type TP2.
If what you care about is the integer field in TP2, then the quickest solution is to change line 78 to:
equalsfunc = (this % var3 % var2 == obj % var3 %var2 )
Or, you can create a defined operator for the "==" operator.
--Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Lorri Menard (Intel) wrote:
If what you care about is the integer field in TP2, then the quickest solution is to change line 78 to:
equalsfunc = (this % var3 % var2 == obj % var3 %var2 )
@lanH, @Lorri,
Thanks for your help. BTW, as var2 is private, the quickest solution may not work properly for the example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops - I muddled OPERATOR(==) and ASSIGNMENT(=). There's no generic binding specification for OPERATOR(==) in the code as shown, etc, etc.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page