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 

Funktionstemplate-argument-deduction

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
christian sulzer
Guest





PostPosted: Sun Nov 23, 2003 1:49 pm    Post subject: Funktionstemplate-argument-deduction Reply with quote



Hallo,
erstmal der Code:

template <class T>
struct Foo {
typedef void (T::*mfn) ();
static void registerMfn (mfn newmfn) {}
};

struct Bar {
void f () {}
};

template <class T>
void doitfn (typename Foo<T>::mfn newmfn) {
Foo<T>::registerMfn (newmfn);
}

int main () {
doitfn<Bar> (&Bar::f); // 1) funktioniert
doitfn (&Bar::f); // 2) geht nicht
return 0;
}

Der Compiler meckert (zurecht glaube ich) bei 2):
doitfn((void Bar::*) ()) does not match doitfn<...>(Foo<_T0>::mfn)

Momentan fällt mir da kein Workaround ein, damit das template-
Argument richtig abgeleitet wird, habt Ihr eine Idee ?

Danke schon mal,
Chris

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Thomas Maeder
Guest





PostPosted: Sun Nov 23, 2003 3:26 pm    Post subject: Re: Funktionstemplate-argument-deduction Reply with quote



"christian sulzer" <christiansulzer (AT) telering (DOT) at> writes:

Quote:
Der Compiler meckert (zurecht glaube ich) bei 2):
doitfn((void Bar::*) ()) does not match doitfn<...>(Foo<_T0>::mfn)

Ich glaube auch zurecht.

Aber die Fehlermeldung wäre falsch, wenn sie so lautete. gcc 3.3.2 sagt:

register.cpp: In function `int main()':
register.cpp:22: error: no matching function for call to `doitfn(void
(Bar::*)())'

, und das scheint mir die zutreffende Setzung der Klammern zu sein.


Quote:
Momentan fällt mir da kein Workaround ein, damit das template-
Argument richtig abgeleitet wird, habt Ihr eine Idee ?

Spricht etwas gegen

template <class T>
void doitfn(void (T::*newmfn)())
{
Foo<T>::registerMfn(newmfn);
}

int main ()
{
doitfn<Bar>(&Bar::f);
doitfn(&Bar::f);
return 0;
}

?

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
christian sulzer
Guest





PostPosted: Sun Nov 23, 2003 5:13 pm    Post subject: Re: Funktionstemplate-argument-deduction Reply with quote




"Thomas Maeder" <maeder (AT) glue (DOT) ch> schrieb im Newsbeitrag

Quote:
Spricht etwas gegen

template <class T
void doitfn(void (T::*newmfn)())
{
Foo }


Hätte ich auch selber draufkommen können, danke.
Hab' mal wieder 'ne Innenkopf-Dauerwelle ;-)

Chris

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) 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.