Design Pattern Examples
Overview of object-oriented design patterns
IIterator< TItemType > Struct Template Referenceabstract

Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 and increment through the items until done. More...

#include <Iterator_Class.h>

Inheritance diagram for IIterator< TItemType >:
Inheritance graph
Collaboration diagram for IIterator< TItemType >:
Collaboration graph

Public Member Functions

virtual ~IIterator ()
 Virtual destructor so this struct can be used as an interface.
 
virtual void Reset ()=0
 Start iteration from beginning of container.
 
virtual bool Next (TItemType &item)=0
 Retrieve the next item from the container.
 

Detailed Description

template<typename TItemType>
struct DesignPatternExamples_cpp::IIterator< TItemType >

Represents an iterator for some type. This is a forward-only iterator in that it can only start at 0 and increment through the items until done.

Template Parameters
TItemTypeThe type of each item provided by the iterator

var iterator = container.GetItems(); for (var item in iterator.Next(); item != null; item = iterator.Next()) { // Use item here }

A generic type is used in this example so I didn't have to come up with either two iterators (one for ItemPair and the other for string) or one iterator that returned an object that would have to be cast to the appropriate type before using.

Definition at line 72 of file Iterator_Class.h.

Constructor & Destructor Documentation

◆ ~IIterator()

virtual ~IIterator ( )
inlinevirtual

Virtual destructor so this struct can be used as an interface.

Definition at line 77 of file Iterator_Class.h.

Member Function Documentation

◆ Next()

virtual bool Next ( TItemType &  item)
pure virtual

Retrieve the next item from the container.

Returns
Returns a TItemType object or null, if there are no more items in the iteration.

Implemented in Iterator< TItemType >.

◆ Reset()

virtual void Reset ( )
pure virtual

Start iteration from beginning of container.

Implemented in Iterator< TItemType >.


The documentation for this struct was generated from the following file: