U
Urs Thuermann
Can I define an iterator for an object of a standard container class
without using the concrete type of that container object?
I tried things like
1 #include <list>
2 void foo(std::list<int> ilist) {
3 ilist.iterator it;
4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
5 }
and
1 #include <list>
2 void foo(std::list<int> ilist) {
3 typeof(ilist)::iterator it;
4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
5 }
For the first code I get
foo.cc:3:11: error: invalid use of 'std::list<int>::iterator'
so at least ilist.iterator seems indeed to be understood as
std::list<int>::iterator. In the second case I get
foo.cc:3:29: error: expected initializer before 'it'
Is there a way to define the iterator without using std::list<int>::iterator
explicitly?
urs
without using the concrete type of that container object?
I tried things like
1 #include <list>
2 void foo(std::list<int> ilist) {
3 ilist.iterator it;
4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
5 }
and
1 #include <list>
2 void foo(std::list<int> ilist) {
3 typeof(ilist)::iterator it;
4 for (it = ilist.begin(); it != ilist.end(); ++it) { *it; }
5 }
For the first code I get
foo.cc:3:11: error: invalid use of 'std::list<int>::iterator'
so at least ilist.iterator seems indeed to be understood as
std::list<int>::iterator. In the second case I get
foo.cc:3:29: error: expected initializer before 'it'
Is there a way to define the iterator without using std::list<int>::iterator
explicitly?
urs