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 

Template-Frage

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





PostPosted: Wed Sep 29, 2004 1:20 pm    Post subject: Template-Frage Reply with quote



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





PostPosted: Wed Sep 29, 2004 1:44 pm    Post subject: Re: Template-Frage Reply with quote



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





PostPosted: Wed Sep 29, 2004 6:05 pm    Post subject: Re: Template-Frage Reply with quote



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
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.