Originally Posted by
john.c
You're right. It's because they made m_spRoot static for some reason.
Just remove the word static from in front of the declaration of m_spRoot,
and remove the bit of code after the class that initializes m_spRoot to nullptr.
Just initialize it to nullptr in the ctor (which is already being done anyway).
There should probably be a destructor.
Thanks for the response. Follow up question:
How does this work?
Code:
// Root of LinkedList wrapped in Iterator type
Iterator begin()
{
return Iterator(m_spRoot);
}
the above call looks like a call to the parameterized constructor which is defined as below
Code:
Iterator(const Node* pNode) noexcept :
m_pCurrentNode (pNode) { }
Which means all it does is set m_pCurrentNode to a node*. But the Iterator begin() function expects a return value of type Iterator. We are just setting a private variable value to something and returning void. How is this working? Why isn't the compiler complaining when we are not returning an Iterator?