templatefrage
-
Hallo zusammen,
ich habe ein kleines Template mit folgendem Code:
namespace A { namespace B { template <typename T> class AddressList { public: AddressList(); [...] const bool contains(T & a); private: typedef std::vector<T> TList; TList queue; }; template <typename T> const bool AddressList<T>::contains(T & a) { TList::iterator it = queue.begin(); while (it != queue.end()) { if (*it == a) { return true; }//End if ++it; }//end while return false; } } }Nun bekomme ich für die iterator Deklaration (Zeile 22) der contains Methode folgende Fehler:
AddressList.h: In member function ‘const bool A::B::AddressList<T>::contains(T&)’: AddressList.h:123: error: expected primary-expression before ‘>’ token AddressList.h:123: error: ‘it’ was not declared in this scopeWas mache ich denn da falsch?
Vielen Dank für Tipps.
uwe
-
typename TList::iterator it;
-
cool, geht! Vielen Dank.

-
Begründung: http://pages.cs.wisc.edu/~driscoll/typename.html
-
arg, zu früh gefreut. nun bekomme ich als fehler:
AddressList.h:173: error: ‘find_if’ is not a member of ‘std’ AddressList.h:175: error: ‘bind2nd’ is not a member of ‘std’ AddressList.h:175: error: ‘equal_to’ is not a member of ‘std’ AddressList.h:175: error: expected primary-expression before ‘>’ token AddressList.h:175: error: expected primary-expression before ‘)’ tokenwas hab ich den nun falsch gemacht? ohne template ging der code ohne probleme. die seite lese ich mir mal durch. danke dafür.
uwe
-
uwerothfeld schrieb:
arg, zu früh gefreut. nun bekomme ich als fehler:
AddressList.h:173: error: ‘find_if’ is not a member of ‘std’ AddressList.h:175: error: ‘bind2nd’ is not a member of ‘std’ AddressList.h:175: error: ‘equal_to’ is not a member of ‘std’ AddressList.h:175: error: expected primary-expression before ‘>’ token AddressList.h:175: error: expected primary-expression before ‘)’ tokenwas hab ich den nun falsch gemacht? ohne template ging der code ohne probleme. die seite lese ich mir mal durch. danke dafür.
uwe
#include <functional> #include <algorithm>vergessen.
Lars
-
upss, peinlich.

danke!