I have code that looks like this:
template<class T>
class list
{
public:
class iterator;
};
template<class T>
class list::iterator
{
public:
iterator();
protected:
list* lstptr;
};
list<T>::iterator::iterator()
{
//???
}
I want to make the constructor of list::iterator to make iterator::lstptr point to the list it’s called from. I.e.:
list xlst;
xlst::iterator xitr;
//xitr.lstptr = xlst
How would I do that?
And also, am I referencing my iterator-constructor right, or should I do something like this:
template<class T>
class list<T>::iterator
{
public:
list<T>::iterator();
protected:
list* lstptr;
};
You can pass the list to the constructor of iterator:
Or, you could make an iterator factory function:
In the factory function case, the
create_iter()function can usethisto refer to the enclosing list.