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.
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