I'm new to the iterator class; not in how to use iterators for containers but how to implement an iterator class. I have two files, a .h and .cpp. Right now, I'm getting a compiler error in my .cpp file that displays "fatal error: 'iterator' is not a class, namespace, or enumeration". I don't understand why its telling me this.
Note: I'm sure there are other errors in my code, but right now I'm just trying to get the existing compiler error resolved.
Base.h
#ifndef Base_h
#define Base_h
class Base {
protected:
std::vector<std::vector<std::string> > vec;
public:
class iterator {
private:
Base* p = nullptr;
size_t x, y;
public:
iterator() = default;
iterator(Base *, size_t, size_t);
~iterator();
iterator &operator++();
Base operator*() const;
}
iterator begin() const;
iterator end() const;
// bunch of other iterator::functions and Base::functions
};
#endif
Base.cpp
iterator::iterator(Base *b, size_t i, size_t j): p(b), x(i), y(j) {}
iterator::~iterator();
// Bunch of other iterator::functions including Base::functions
Compiler Error
Base.cc:254:13: fatal error: 'iterator is not a class, namespace, or enumeration
iterator::iterator(Base *b, size_t i, size_t j): p(b), x(i), y(j) {}
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/iterator:522:29: note: 'iterator' declared here
struct _LIBCPP_TEMPLATE_VIS iterator