- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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!
- Balises:
- Intel® Fortran Compiler
Lien copié
3 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Generic functions are distinguished by their arguments: new_t1 and new_t2 have no arguments. Generic resolution isn't done by function result type.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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...
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable