T
thekestrel
Hi,
I'm trying to iterate over the values of a list that has a
templated type and I'm having trouble with the syntax, could anyone
offer somehelp. Simplified version...
#include <list>
#include <iterator>
using namspace std;
template <class T>
class test {
public:
void add(T a) { l.push.back(a); }
void print(void) {
list<T>::iterator itr; // <-- compile error here
// ... do print thang
}
private:
list<T> l;
}
int main(void) {
test<float> a;
a.add(5.0);
}
Compilation fails in the list iterator declaration with:
In member function 'void test<T>:rint(): error: expected ';' before
itr.
I can't find a list example using iterators and templates for the life
of me so I'm hoping someone can help me with some n00b syntax =).
I'm trying to iterate over the values of a list that has a
templated type and I'm having trouble with the syntax, could anyone
offer somehelp. Simplified version...
#include <list>
#include <iterator>
using namspace std;
template <class T>
class test {
public:
void add(T a) { l.push.back(a); }
void print(void) {
list<T>::iterator itr; // <-- compile error here
// ... do print thang
}
private:
list<T> l;
}
int main(void) {
test<float> a;
a.add(5.0);
}
Compilation fails in the list iterator declaration with:
In member function 'void test<T>:rint(): error: expected ';' before
itr.
I can't find a list example using iterators and templates for the life
of me so I'm hoping someone can help me with some n00b syntax =).