 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
christian sulzer Guest
|
Posted: Fri Nov 14, 2003 11:54 pm Post subject: template-Spezialisierung |
|
|
Hallo,
bei folgendem Code meckert der Compiler
(Metrowerks Code-Krieger
"illegal explicit template specialization"
an Stelle 1)
// hpp-Datei
template <class T>
class Foo {
public:
typedef typename T::src_result_type src_result_type;
typedef typename T::dst_result_type dst_result_type;
dst_result_type operator () (const src_result_type &src);
};
template <>
class Foo<MyType> {
public:
typedef typename MyType::src_result_type src_result_type;
typedef typename MyType::dst_result_type dst_result_type;
dst_result_type operator () (const src_result_type &src);
private:
struct CalcA {
bool operator () (const src_result_type &src);
};
};
//in der cpp-Datei:
// ...
// *** das werkt nicht ***
template <>
bool Foo<MyType>::CalcA::operator ()
(const Foo<MyType>::src_result_type &src) { // <---1)
....
}
// ******************
Bin mir ziemlich sicher, daß das ein
Syntaxfehler ist, aber wie schreibt man das richtig ?
(Inline im Klassenrumpf wird der operator jedenfalls übersetzt)
Danke für Euere Bemühungen,
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 |
|
 |
Joerg Barfurth Guest
|
Posted: Sun Nov 16, 2003 10:33 pm Post subject: Re: template-Spezialisierung |
|
|
Hi,
christian sulzer <christiansulzer (AT) telering (DOT) at> wrote:
| Quote: | Hallo,
bei folgendem Code meckert der Compiler
(Metrowerks Code-Krieger
"illegal explicit template specialization"
an Stelle 1)
|
Bei anderen Compilern habe ich schon aussagekräftigere Varianten dieser
Fehlermeldung gelesen.
| Quote: | // hpp-Datei
template <class T
class Foo {
....
};
|
Jetzt hast du ein Klassentemplate Foo<...>
| Quote: | template
class Foo<MyType> {
public:
typedef typename MyType::src_result_type src_result_type;
typedef typename MyType::dst_result_type dst_result_type;
dst_result_type operator () (const src_result_type &src);
private:
struct CalcA {
bool operator () (const src_result_type &src);
};
};
|
Mit der expliziten Spezialisierung, hast du dem Compiler mitgeteilt,
dass es eine besondere Klasse gibt, die er verwenden soll, wenn Foo<...>
für MyType spezialisiert verwendet wird.
Der Name dieser Klasse ist Foo<MyType>. Diese Klasse ist eine Klasse,
kein Template mehr (obwohl sie einen Namen hat, der ein 'template-id'
ist).
Nachdem du also eine explizite Spezialisierung deklariert hast,
behandelst du den Namen als ganz normalen Kassennamen, nicht als
Templatenamen.
| Quote: | //in der cpp-Datei:
// ...
// *** das werkt nicht ***
template
bool Foo<MyType>::CalcA::operator ()
(const Foo<MyType>::src_result_type &src) { // <---1)
...
}
// ******************
|
Hier versuchst du eine Funktion explizit zu spezialisieren, die gar kein
Template ist (auch nicht Member eines Klassentemplates). operator() ist
hier einfach Member der Klasse Foo
Lass einfach das 'template<>' an dieser Stelle weg.
| Quote: | Bin mir ziemlich sicher, daß das ein
Syntaxfehler ist, aber wie schreibt man das richtig ?
(Inline im Klassenrumpf wird der operator jedenfalls übersetzt)
|
HTH, Joerg
--
Jörg Barfurth [email]barfurth (AT) gmx (DOT) net[/email]
<<<<<<<<<<<<< using std::disclaimer; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
Software Developer http://util.openoffice.org
StarOffice Configuration # Deutsch:http://de.openoffice.org
--
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: Mon Nov 17, 2003 3:39 pm Post subject: Re: template-Spezialisierung |
|
|
"Joerg Barfurth" <barfurth (AT) gmx (DOT) net> schrieb im Newsbeitrag
news:1g4jhzv.8r6uy510ivn5eN%barfurth (AT) gmx (DOT) net...
| Quote: | Lass einfach das 'template<>' an dieser Stelle weg.
|
Genau das hat's gebracht !
Danke nochmals,
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
|
|