I can't understand why my code doesn't compile.
template<class Priority,class T> class PriorityQueue {
public:
class Iterator;
//some methods
Iterator begin() const;
Iterator end() const;
};
and then in the Iterator class:
template<class Priority,class T>
class PriorityQueue<Priority,T>::Iterator {
//implement ctor,operator++,==etc.
Almost all the 84-errors I get are about these functions:
template<class Priority,class T>
Iterator<Priority,T> PriorityQueue<Priority,T>::begin() const{
return Iterator<Priority,T>(firstNode);
}
template<class Priority,class T>
Iterator<Priority,T> PriorityQueue<Priority,T>::end() const{
return Iterator<Priority,T>(nullptr);
}
The error is: Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int. And: Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int and: Error 1 error C2143: syntax error : missing ';' before '<'. All regarding the method begin() and end() (in their first line Iterator PriorityQueue::begin()). EDIT: I tried using typename but it didn't help.
class Iterator;is a forward declaration you can't declare classes and then define them. - 101010Iterator(i.e.class Iterator { ... };) where you currently have the declaration (insidePriorityQueue). - Tony Delroy