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 

Pointeur sur fonction template

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





PostPosted: Thu Mar 23, 2006 11:06 am    Post subject: Pointeur sur fonction template Reply with quote



Bonjour,
Je désire définir un pointeur vers une fonction template (en
l'occurence std::real() de <complex>).
Cette fonction ayant une version const et non const, et voulant un
pointeur vers la version const, j'écris :

#include <complex>

int main()
{
const float& (*pc)( const std::complex<float>& ) = std::real<
std::complex<float> >;
return 0;
}

Avec g++, cela me dit :

titi.cpp:12: error: no matches converting function 'real' to type
'const float& (*)(const struct std::complex<float>&)'
/usr/include/c++/4.0.2/complex:531: error: candidates are:
template<class _Tp> _Tp& std::real(std::complex<_Tp>&)
/usr/include/c++/4.0.2/complex:536: error:
template<class _Tp> const _Tp& std::real(const std::complex<_Tp>&)

Et la, j'avoue que je ne comprend pas, d'autant que le deuxième
candidat est exactement celui qui m'intéresse.
Est-ce que quelqu'un aurait une idée pour définir un pointeur vers
cette fonction ?

Merci d'avance.
Back to top
Marc Duflot
Guest





PostPosted: Thu Mar 23, 2006 1:06 pm    Post subject: Re: Pointeur sur fonction template Reply with quote



David Tschumperlé wrote:

Quote:
const float& (*pc)( const std::complex<float>& ) = std::real
std::complex<float> >;

= std::real<float>;
Back to top
David Tschumperlé
Guest





PostPosted: Thu Mar 23, 2006 2:06 pm    Post subject: Re: Pointeur sur fonction template Reply with quote



Ha oui d'accord, merci !
Back to top
David Tschumperlé
Guest





PostPosted: Thu Mar 23, 2006 2:06 pm    Post subject: Re: Pointeur sur fonction template Reply with quote

Si effectivement ca marche !
Je suis étonné par ces affectations qui prennent en compte le
contexte (membre de gauche)
pour trouver le bon choix.

Merci en tout cas.
Back to top
kanze
Guest





PostPosted: Thu Mar 23, 2006 2:06 pm    Post subject: Re: Pointeur sur fonction template Reply with quote

Marc Duflot wrote:
Quote:
David Tschumperlé wrote:

const float& (*pc)( const std::complex<float>& ) = std::real
std::complex<float> >;

= std::real<float>;

= &std::real ;

tout court ne marche pas ? (J'ai l'impression qu'il doit
marcher, mais il faut dire que le texte de la norme ici n'est
pas particulièrement facile à lire.)

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Back to top
kanze
Guest





PostPosted: Fri Mar 24, 2006 9:06 am    Post subject: Re: Pointeur sur fonction template Reply with quote

David Tschumperlé wrote:
Quote:
Si effectivement ca marche !
Je suis étonné par ces affectations qui prennent en compte le
contexte (membre de gauche)
pour trouver le bon choix.

C'est un cas spécial. Il n'entre en jeu que si on prend
l'adresse d'une fonction (avec & ou implicitement), voir §13.4.

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
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.