 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Oliver Fischer Guest
|
Posted: Wed Sep 29, 2004 1:20 pm Post subject: Template-Frage |
|
|
Hallo Gruppe,
folgendes Beispielprogramm sei gegeben:
#include <iostream>
#include <list>
#include <sstream>
#include <string>
using namespace std;
template<class T> string toString(const T& list)
{
T::const_iterator anfang;
stringstream ss;
ss << "Anfang(";
ss << ")Ende";
return ss.str();
}
int main(int, char**)
{
list
cout << toString(meineListe) << endl;
return 0;
}
In der Methode toString versuche ich einen const_iterator für T
anzulegen. Leider meldet mir der GCC nur "Parse error". Ich müßte nun
gerne, ob wie ich dieses Template umzuformulieren habe und warum es so
nicht geht.
Vielen lieben Dank
Oliver Fischer
--
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 |
|
 |
Christoph Rabel Guest
|
Posted: Wed Sep 29, 2004 1:44 pm Post subject: Re: Template-Frage |
|
|
Oliver Fischer wrote:
| Quote: |
template<class T> string toString(const T& list)
{
T::const_iterator anfang;
|
Hier fehlt ein typename:
typename T::const_iterator anfang;
mfg
Christoph
--
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 |
|
 |
Rolf Magnus Guest
|
Posted: Wed Sep 29, 2004 6:05 pm Post subject: Re: Template-Frage |
|
|
Oliver Fischer wrote:
| Quote: | Hallo Gruppe,
folgendes Beispielprogramm sei gegeben:
#include <iostream
#include
#include
#include
using namespace std;
template
{
T::const_iterator anfang;
|
Du mußt dem Compiler hier sagen, daß T::const_iterator ein Typ ist Da er das
nicht in solchen Fällen manchmal nicht so einfach rausbekommen kann, nimmt
er hier wohl an, es sei eine Membervariable. Du mußt bei vom Template-
Parameter abhängigen Typen daher sowas schreiben:
typename T::const_iterator anfang;
| Quote: | stringstream ss;
ss << "Anfang(";
ss << ")Ende";
return ss.str();
}
int main(int, char**)
{
list
cout << toString(meineListe) << endl;
return 0;
}
In der Methode toString versuche ich einen const_iterator für T
anzulegen. Leider meldet mir der GCC nur "Parse error". Ich müßte nun
gerne, ob wie ich dieses Template umzuformulieren habe und warum es so
nicht geht.
Vielen lieben Dank
Oliver Fischer
|
--
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
|
|