In this recipe, we will implement our own iterator class, and then, we will iterate through it:
- First, we include the header, which enables us to print to the terminal:
#include <iostream>
- Our iterator class will be called num_iterator:
class num_iterator {
- Its only data member is an integer. That integer is used for counting. The constructor is for initializing it. It is generally a good form to make constructors explicit, which create a type from another type to avoid accidental implicit conversion. Note that we also provide a default value for position. This makes the instances of the num_iterator class default-constructible. Although we will not use the default constructor in the whole recipe, this is really important ...