Re: std::list<T>::iterator
In article
<1029279d-c9c0-4eb5-843e-f4607c8e352d@z72g2000hsb.googlegroups.com>,
Isliguezze <isliguezze@gmail.com> wrote:
Does anybody know how to make a wrapper for that iterator? Here's my
wrapper class for std::list:
template <class T> class List {
private:
std::list<T> *lst;
public:
List() { lst = new std::list<T>(); }
List(const List<T> &rhs) { lst = new std::list<T>(*rhs.lst); }
List(int n, const T& value) { lst = new std::list<T>(n, value); }
~List() { delete lst; }
void push_back(const T& value) { lst->push_back(value); }
void push_front(const T& value) { lst->push_front(value); }
void pop_back() { lst->pop_back; }
void pop_front() { lst->pop_front; }
void remove(const T& value) { lst->remove(value); }
};
First, don't contain the std::list by pointer.
template < typename T >
class List
{
std::list<T> rep;
public:
typedef typename std::list<T>::iterator iterator;
List():rep() { }
List( int n, const T& value ): rep( n, value ) { }
void push_back( const T& value ) { rep.push_back( value ); }
// etc...
iterator begin() { return rep.begin(); }
};