- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I'm testing some modification in my code and I found a problem with the generic interface definitions. In the next sample, the compiler consider ambigous the definition of the procedure, but are different types!
If someone can help me with this, or explain me what is wrong here, please.
I understand that the compiler should recognize each procedure, or not?
thanks!
I'm testing some modification in my code and I found a problem with the generic interface definitions. In the next sample, the compiler consider ambigous the definition of the procedure, but are different types!
If someone can help me with this, or explain me what is wrong here, please.
[cpp]module types
implicit none
private
type t1_t
real(8) :: a
end type
type t2_t
integer :: a
end type
interface new
module procedure new_t1, new_t2
end interface
public:: t1_t, t2_t, new
contains
function new_t1()
type(t1_t), pointer :: new_t1
allocate(new_t1)
end function
function new_t2()
type(t2_t), pointer :: new_t2
allocate(new_t2)
end function
end module types
program test
use types
implicit none
type(t1_t), pointer :: t1
type(t2_t), pointer :: t2
t1 => new()
t2 => new()
end program test[/cpp]
I understand that the compiler should recognize each procedure, or not?
thanks!
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generic functions are distinguished by their arguments: new_t1 and new_t2 have no arguments. Generic resolution isn't done by function result type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
Generic functions are distinguished by their arguments: new_t1 and new_t2 have no arguments. Generic resolution isn't done by function result type.
Ok, thanks Steve.
I will change the function to subroutine.
Maybe in the future can be possible to verify the result type in functions...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If by that you mean the language will allow function result types to participate in generic resolution, that won't happen as there's nothing available to base the selection on. Fortran does not "look at" what is on the left side of an assignment when deciding on the meaning of the right side.
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