I am currently creating a circular linked class and I am having trouble with the operator= function. This is what I have.
Code:
template <class Object>
const CircleList<Object> & CircleList<Object>::operator=(const CircleList & rhs)
{
clear();
CircleListItr<Object> ritr = rhs.returnBase();
CircleListItr<Object> tempItr = rhs.returnBase();
++ritr;
for ( ; ritr != tempItr; ++ritr)
insert((*ritr).element);
return *this;
}
Code:
template <typename Object>
void CircleList<Object>::insert (const Object & x)
{
CircleListNode<Object>* p = theBase;
if (p->next == 0)
{
p->next = new CircleListNode<Object> ( x, p, p);
theBase->previous = p->next;
}
else
{
while (p->next != theBase)
{
p = p->next;
}
p->next = new CircleListNode<Object> ( x, theBase, p);
theBase->previous = p->next;
}
}
In the main function I have List 1 which is 3 8 6 5 9 2 1 .
So I create a List2, and do List2 = List1;
When I run the code, I determine through debugging it only runs through the while loop four times, inserting the first four items. It does not insert the 9 or anything after it and it terminates. Anyone know where I am going wrong?