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 

Probleme beim Kompilieren beim Verwendung von STL Iteratoren

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





PostPosted: Mon May 01, 2006 12:21 pm    Post subject: Probleme beim Kompilieren beim Verwendung von STL Iteratoren Reply with quote



Hallo NG,

ich komm und komm nicht dahinter,
warum sich der unten angeführte Code nicht compilieren lässt.

Der Compiler beschwert sich in der Zeile "std::vector<T>..." mit der
Fehlermeldung: error: expected ';' before 'iter'


------------------- CUT HERE -------------------

#ifndef MYHELPERCLASS_H_
#define MYCLASS_H_

#include <iostream>
#include <vector>

class MyHelperClass
{
template<typename T>
void listElements(const std::vector<T> &p)
{
std::vector<T>::const_iterator iter = p.begin();
.....
.....
.....
}
};

#endif /*MYHELPERCLASS_H_*/

------------------- CUT HERE -------------------


Wenn ich die Headerdatei MyHelperClass in meinem Programm einbinde, kommt
die oben abgeführte Fehlermeldung. Ich erhalte diese Fehlermeldungen auch
an anderen Stellen, wo ich Iteratoren einsetze. Verwende ich die Methode
listElement(..) aber als Funktion (z.b. in der main.cpp), dann gibt es
keine Probleme bei der Kompilierung und das Programm ist lauffähig.

Könnt Ihr mir da weiterhelfen?
Danke im Voraus um Eure Antworten

Mike

--
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 Kliemt
Guest





PostPosted: Mon May 01, 2006 9:06 pm    Post subject: Re: Probleme beim Kompilieren beim Verwendung von STL Iterat Reply with quote



Michael <apue05 (AT) gmx (DOT) net> writes:

Quote:
Hallo NG,

ich komm und komm nicht dahinter, warum sich der unten angeführte Code
nicht compilieren lässt.

[...]

Quote:
------------------- CUT HERE -------------------

#ifndef MYHELPERCLASS_H_ #define MYCLASS_H_

#include <iostream> #include <vector

class MyHelperClass {
template<typename T
void listElements(const std::vector<T> &p)
{
std::vector<T>::const_iterator iter = p.begin();
.....
.....
.....
} };

#endif /*MYHELPERCLASS_H_*/

man typename

hth,

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
Thomas Maeder
Guest





PostPosted: Mon May 01, 2006 9:06 pm    Post subject: Re: Probleme beim Kompilieren beim Verwendung von STL Iterat Reply with quote



Michael <apue05 (AT) gmx (DOT) net> writes:

Quote:
Der Compiler beschwert sich in der Zeile "std::vector<T>..." mit der
Fehlermeldung: error: expected ';' before 'iter'


------------------- CUT HERE -------------------

#ifndef MYHELPERCLASS_H_
#define MYCLASS_H_

#include <iostream
#include <vector

class MyHelperClass
{
template<typename T
void listElements(const std::vector<T> &p)
{
std::vector<T>::const_iterator iter = p.begin();

Der Compiler weiss an dieser Stelle nicht, was durch den Namen
std::vector<T>::const_iterator benannt wird, weil dieser Name ein
sog. "abhängiger Name" ("dependant name") ist. Jede Spezialisierung
des Templates std::vector (das in Standardese ein benutzerdefinierter
Typ ist) könnte den Namen ja für etwas anderes brauchen, mal für einen
Typ, mal für eine Zahl usw.

Der Standard fordert vom Compiler, anzunehmen, dass solche Namen
*nicht* einen Typ benennen, wenn das Programm das nicht explizit sagt,
und zwar so:

typename std::vector<T>::const_iterator iter = p.begin();

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