C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problème sur l'argument d'une fonction template

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Helfer Thomas
Guest





PostPosted: Tue Nov 07, 2006 10:11 am    Post subject: Problème sur l'argument d'une fonction template Reply with quote



Bonjour,

j'aimerai comprendre pourquoi le code suivant ne compile pas :

#include<iostream>
#include<cstdlib>

template<typename T>
struct Id
{
typedef T type;
};

template<typename T>
void f(typename Id<T>::type a)
{
using namespace std;
cout << a << endl;
}

int main(void)
{
f(12.);
f(12);
return EXIT_SUCCESS;
}

gcc me donne le message d'erreur suivant :
Test.cxx:26: error: no matching function for call to f(double)
Test.cxx:27: error: no matching function for call to f(int)

Est-ce normal ?

Cordialement,

Helfer Thomas
Back to top
Jean-Marc Bourguet
Guest





PostPosted: Tue Nov 07, 2006 10:11 am    Post subject: Re: Problème sur l'argument d'une fonction template Reply with quote



Helfer Thomas <helferthomas (AT) free (DOT) fr> writes:

Quote:
Bonjour,

j'aimerai comprendre pourquoi le code suivant ne compile pas :

#include<iostream
#include<cstdlib

template<typename T
struct Id
{
typedef T type;
};

template<typename T
void f(typename Id<T>::type a)
{
using namespace std;
cout << a << endl;
}

int main(void)
{
f(12.);
f(12);
return EXIT_SUCCESS;
}

gcc me donne le message d'erreur suivant :
Test.cxx:26: error: no matching function for call to f(double)
Test.cxx:27: error: no matching function for call to f(int)

Est-ce normal ?

Oui. Il n'est pas possible de deduire le parametre template en
suivant les regles du C++. Tu peux les specifier toi-meme:

f<double>(12.);
f<int>(12);

A+

--
Jean-Marc
Back to top
Gabriel Dos Reis
Guest





PostPosted: Tue Nov 07, 2006 10:11 am    Post subject: Re: Problème sur l'argument d'une fonction template Reply with quote



Helfer Thomas <helferthomas (AT) free (DOT) fr> writes:

| Bonjour,
|
| j'aimerai comprendre pourquoi le code suivant ne compile pas :
|
| #include<iostream>
| #include<cstdlib>
|
| template<typename T>
| struct Id
| {
| typedef T type;
| };
|
| template<typename T>
| void f(typename Id<T>::type a)
^^^^

Salut Thomas. Laurent a posé une question similaire récemment : le
paramètre de template « T » apparait dans un contexte non-déductible.
Donc l'appel « ordinaire »

[...]

| f(12.);

ne peut pas marcher -- il te faudrait explicitement spécifier
l'argument de template « f<double>(12.) ».

-- Gaby
Back to top
Helfer Thomas
Guest





PostPosted: Sat Nov 11, 2006 5:27 pm    Post subject: Re: Problème sur l'argument d'une fonction template Reply with quote

Merci pour vos réponses.

Le Tue, 07 Nov 2006 09:22:04 +0100, Helfer Thomas a écrit :

Quote:
Bonjour,

j'aimerai comprendre pourquoi le code suivant ne compile pas :

#include<iostream
#include<cstdlib

template<typename T
struct Id
{
typedef T type;
};

template<typename T
void f(typename Id<T>::type a)
{
using namespace std;
cout << a << endl;
}

int main(void)
{
f(12.);
f(12);
return EXIT_SUCCESS;
}

gcc me donne le message d'erreur suivant :
Test.cxx:26: error: no matching function for call to f(double)
Test.cxx:27: error: no matching function for call to f(int)

Est-ce normal ?

Cordialement,

Helfer Thomas
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
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 © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.