Still No dice... now I get
Warning: RAList<T>::iterator dependent name is not a type
Error: syntax error missing ; before +
Error: missing type specifier - int assumed
Error: unable to recover from previous error
Here is the full code... i taken out my + operator as it is wrong anyways and have your in as a non member function.
P.S I really appriciate your help
Code:
#ifndef _GUARD_RALIST_
#define _GUARD_RALIST_
#include <list>
#include <cassert>
template <typename T>
class RAList : public std::list<T>
{
private:
list<iterator> _lstInsertHistory; // Keeps history of each element added using insert()
list<T> _lstRemoveHistory; // Keeps history of each element removed using remove()
iterator _currentIt; // Keeps the current iterator, used for + operator
public:
// Default Constructor
RAList() : std::list<T>(), _lstInsertHistory(), _lstRemoveHistory(), _currentIt( begin() )
{
assert( _lstInsertHistory.empty() );
assert( _lstRemoveHistory.empty() );
assert( empty() );
}
// Destructor
~RAList()
{
_lstInsertHistory.clear();
_lstRemoveHistory.clear();
clear();
assert( _lstInsertHistory.empty() );
assert( _lstRemoveHistory.empty() );
assert( empty() );
}
reference operator [] ( size_type const& iNum )
{
iterator it = 0;
( iNum > static_cast<size_type>( size() / 2) ) ? it = end() : it = begin();
if ( it == end() )
for( size_type i = size(); i != iNum; --i)
--it;
else
for( size_type i = 0; i != iNum; ++i)
++it;
return *it;
}
iterator insert( iterator it, const T& x = T( ) )
{
_lstInsertHistory.push_front( list<T>::insert( it, x ) );
return _lstInsertHistory.front();
}
void undo_last_insert()
{
if ( _lstInsertHistory.size() <= 0 )
return;
for ( list<iterator>::iterator it1 = _lstInsertHistory.begin(); it1 != _lstInsertHistory.end(); ++it1)
{
iterator it = begin();
for( size_type i = 0; i <= size(); ++i )
{
if ( it == *it1 )
{
erase( it );
_lstInsertHistory.erase( it1 );
return;
}
else
++it;
}
}
}
void remove( const T& _Val )
{
for( iterator it = begin(); it != end(); ++it )
{
if ( *it == _Val )
{
_lstRemoveHistory.push_back( _Val );
list<T>::remove( _Val );
break;
}
}
}
void undo_last_remove()
{
if ( _lstRemoveHistory.size() <= 0 )
return;
push_back( _lstRemoveHistory.back() );
_lstRemoveHistory.pop_back();
}
};
template <typename T>
RAList<T>::iterator operator+ (RAList<T>::iterator iter, size_t inc)
{
std::advance(iter, inc);
return iter;
}
#endif