creating templated iterator

I use c++11. I wrote a priority queue and an iterator class for it. But when I use the iterator I have to write:

1
2
3
4
5
6
7
8
9
10
for(Iterator<int,int> iterator=pq.begin();iterator != pq.end();
           ++iterator){
       cout << iterator.node->value;
   }
but I want to write:

for(iterator iter=pq.be
       cout << iter.node-gin();iter != pq.end();
           ++iter){>value;
   }

I tried typdef or using but it didn't help, thanks for help!. I tried:

1
2
template<class Priority,class T> class PriorityQueue {
typedef Iterator<Priority,T> iterator;
1. Make this typedef public
2. Make sure that you are using it as PriorityQueue<int, int>::iterator
3. Forget about first two points ansd use auto instead of manually writing type.
Thanks for the reply, the typedef is public. but when I try to write PriorityQueue<int, int>::iterator, it says that PriorityQueue<int, int> isn't a namespace.
Last edited on
If you are using PriorityQueue<int, int> inside another template, you might have to write typename before it. Otherwise it should work: http://ideone.com/bbhCl1

Did you try to use auto instead? (Requires C++11)
auto works fine, Thanks! (and I also tried the first option but I guese auto is easier).
Topic archived. No new replies allowed.