Help with Iterator for templated list.

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>::print(): 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 =).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top