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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top