Iterator subclass separate inclusion
up vote
2
down vote
favorite
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
c++ iterator
add a comment |
up vote
2
down vote
favorite
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
c++ iterator
2
iterator
is a nested class: try qualifiying the implementation in cpp file withBase::iterator::iterator
Or try avoid to declare iterator as nested class
– Gian Paolo
Nov 19 at 23:31
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
1
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
the following declarationBase operator*() const;
seems suspicious. You really want to return a copy ofBase
?
– Phil1970
Nov 20 at 2:01
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
c++ iterator
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
c++ iterator
c++ iterator
asked Nov 19 at 23:27
N. Colostate
356
356
2
iterator
is a nested class: try qualifiying the implementation in cpp file withBase::iterator::iterator
Or try avoid to declare iterator as nested class
– Gian Paolo
Nov 19 at 23:31
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
1
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
the following declarationBase operator*() const;
seems suspicious. You really want to return a copy ofBase
?
– Phil1970
Nov 20 at 2:01
add a comment |
2
iterator
is a nested class: try qualifiying the implementation in cpp file withBase::iterator::iterator
Or try avoid to declare iterator as nested class
– Gian Paolo
Nov 19 at 23:31
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
1
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
the following declarationBase operator*() const;
seems suspicious. You really want to return a copy ofBase
?
– Phil1970
Nov 20 at 2:01
2
2
iterator
is a nested class: try qualifiying the implementation in cpp file with Base::iterator::iterator
Or try avoid to declare iterator as nested class– Gian Paolo
Nov 19 at 23:31
iterator
is a nested class: try qualifiying the implementation in cpp file with Base::iterator::iterator
Or try avoid to declare iterator as nested class– Gian Paolo
Nov 19 at 23:31
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
1
1
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
the following declaration
Base operator*() const;
seems suspicious. You really want to return a copy of Base
?– Phil1970
Nov 20 at 2:01
the following declaration
Base operator*() const;
seems suspicious. You really want to return a copy of Base
?– Phil1970
Nov 20 at 2:01
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384120%2fiterator-subclass-separate-inclusion%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
iterator
is a nested class: try qualifiying the implementation in cpp file withBase::iterator::iterator
Or try avoid to declare iterator as nested class– Gian Paolo
Nov 19 at 23:31
I believe that worked. Although, it came up with another compiler error but one I can deal with. Thanks. If all else fails, I may avoid a nested class. Thanks.
– N. Colostate
Nov 19 at 23:36
1
well, as a start, why do you need a nested class? (actually, I just asked this myself) see also stackoverflow.com/questions/4571355/…
– Gian Paolo
Nov 19 at 23:40
I decided on using a nested class through examples provided from various .edu addresses. So, I assume it was standard practice. From the comments so far, it doesn't seem that way.
– N. Colostate
Nov 19 at 23:44
the following declaration
Base operator*() const;
seems suspicious. You really want to return a copy ofBase
?– Phil1970
Nov 20 at 2:01