 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
christian sulzer Guest
|
Posted: Sun Nov 23, 2003 1:49 pm Post subject: Funktionstemplate-argument-deduction |
|
|
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
|
Posted: Sun Nov 23, 2003 3:26 pm Post subject: Re: Funktionstemplate-argument-deduction |
|
|
"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
|
Posted: Sun Nov 23, 2003 5:13 pm Post subject: Re: Funktionstemplate-argument-deduction |
|
|
"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 |
|
 |
|
|
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
|
|