Reputation: 11730
I want to create a custom container that supports iterators. It looks like this:
class SomeContainer {
...
public:
typedef SomeIterator iterator;
iterator begin() { ... }
iterator end() { ... }
};
Then I create an iterator for this:
class SomeIterator: public boost::iterator_facade<
SomeIterator,
SomeType,
boost::bidirectional_traversal_tag> {
...
}
The problem with this is the following. If I declare SomeContainer
before SomeiIterator
and forward declare SomeIterator
, then the compiler complains st the begin()
and end()
methods that SomeIterator
is an incomplete type. However, if I do it the other way, then the problem is the other way around: SomeContainer
is incomplete.
Upvotes: 0
Views: 173
Reputation: 35449
It is possible to satisfy your first requirement partially, in that you can define everything in the header except for begin
and end
that will need to be declared inline
and defined outside the SomeContainer
definition, and after the SomeIterator
definition (which completes the type). This assumes you keep the current order of definition (SomeContainer
before SomeIterator
), which I suggest you keep.
Otherwise, you can certainly ditch inline
(implicit or otherwise) and define outside the class definitions. By doing so, both types will be complete from those definitions.
Upvotes: 1