List Implementation

below is the code which is same(almost) as given in MARK ALLEN WEISS
#include<iostream>



template < typename Object >
class List
{
private:
struct Node
{
Object data;
Node *next;
Node *prev;
Node(const Object & info = Object(), Node * p= NULL, Node *n = NULL)
:data(info),next(n),prev(p)
{ }
};
public:


class const_iterator
{
public:
const_iterator()
:current(NULL)
{
}

const_iterator & operator ++()
{
current=current->next;
return *this;
}

const_iterator operator ++(int )
{
const_iterator old(current);
current=current->next;
return old;
}

const Object & operator *() const
{

return retrieve();
}

bool operator ==(const const_iterator & rhs) const
{
return( current==rhs.current);
}
bool operator !=(const const_iterator & rhs) const
{
return ( current !=rhs.current);
}

protected:
Node * current;

Object & retrieve() const
{
return current->data;
}

const_iterator(Node * p)
:current(p) { }

friend class List<Object>;
};

class iterator : public const_iterator
{
public:
iterator()
{
}
iterator & operator ++()
{
current=current->next;
return *this;
}

iterator operator ++(int )
{
const_iterator old(current);
current=current->next;
return old;
}

Object & operator *()
{

return retrieve();
}

const Object & operator *() const
{

return retrieve();
}

protected:
iterator(Node * p)
:const_iterator(p)
{ }
friend class List<Object>;
};
List()
{
init();
}
List(const List & rhs)
{
init();
*this=rhs;
}
~List()
{
clear();
delete head;
delete tail;
}
const List & operator = (const List & rhs)
{
if(this == &rhs)
{ }
else
{
clear();
for(const_iterator itr=rhs.begin();itr!=rhs.end();++itr)
{
push_back(*itr);
}
}
return *this;
}
iterator begin()
{
return iterator(head->next);
}
const_iterator begin() const
{
return const_iterator(head->next);
}
iterator end()
{
return iterator(tail);
}
const_iterator end() const
{
return const_iterator(tail);
}
int size() const
{
return theSize;
}
bool empty() const
{
if(theSize == 0)
return true;
else
return false;
}

void clear()
{
while( !empty() )
pop_front();
}
Object & front()
{
return *begin();
}
const Object & front() const
{
return *begin();
}

Object & back()
{
return *--end();
}
const Object & back() const
{
return *--end()();
}

void push_front(const Object & x)
{
insert(begin(),x);
}
void push_back(const Object & x)
{
insert(end(),x);
}
void pop_front()
{
erase(begin());
}
void pop_back()
{
erase(--end());
}

iterator insert(iterator itr,const Object & x)
{
Node *tempptr =new Node(x);
itr.current->prev->next=tempptr;
tempptr->prev=itr.current->prev;
itr.current->prev=tempptr;
tempptr->next=itr.current;
++theSize;
return iterator(tempptr);
}


iterator erase(iterator itr)
{
Node *p;
iterator retval(p->next);
p->prev->next=p->next;
p->next->prev=p->prev;
delete p;
--theSize;

return retval;

}

iterator erase(iterator start , iterator end)
{
for(iterator itr=start; itr != end; )
itr=erase(itr);
}

private:
Node * head;
Node * tail;
int theSize;
void init()
{
theSize=0;
head=new Node;
tail=new Node;
head->next=tail;
tail->prev=head;
}

};




but their are some error in code which i m not able to solve

*79 C:\Dev-Cpp\work1\List.cpp `current' undeclared (first use this function)
*85 C:\Dev-Cpp\work1\List.cpp `current' undeclared (first use this function)
*93 C:\Dev-Cpp\work1\List.cpp there are no arguments to `retrieve' that depend on a template parameter, so a declaration of `retrieve' must be available

PS : this is my first post if i had made some mistake , plz correct me

somebody help,plz !!
Topic archived. No new replies allowed.