   Encapsulating STL Iterator
  Hi all, it's me again... I'm giving up after 2hours of trying and searching a way of encapsulating a list<T>::iterator into one of my template.I'll post the revelant code if anyone have suggestion or comments, i'm listening.template <typename T> class List : public IList<T>{public:  template <typename T> class Enumerator : public IEnumerator<T>  {  private:    // !!! THIS IS MY PARTY BREAKER LINE !!!    list<T>::iterator iter;  public:    Enumerator(/*list<T>::iterator iter*/)    { //this->iter = iter;    }   virtual ~Enumerator()    {    }  public:    T getCurrent(){ throw NotImplementedException();    }  public:    bool MoveNext(){ throw NotImplementedException();    }    void Reset(){    }   };public:  // Returns an enumerator that iterates through the List.   virtual IEnumerator<T>* GetEnumerator()  {    Enumerator<T>* enumerator = new Enumerator<T>(/* innerList.begin() */);    return enumerator;  }};For thoses who are asking why i'm doing this, i hate STL, i love C# generics.So, a big part of the C#'s System.Collections.Generic namespace is going to be functional in my C++ framwork, if i can find a way of fixing my problem with std::iterator in the Enumerator class.Edit: Oh ya, the error: error C2146: syntax error : missing ';' before identifier 'iter'Regards,Jonathan   
typename list<T>::iterator iter;list<T> is a dependent type, therefore the compiler interprets list<T>::iterator as a static member variable. typename tells it it really is a nested type.Quote:virtual IEnumerator<T>* GetEnumerator()  {    Enumerator<T>* enumerator = new Enumerator<T>(/* innerList.begin() */);    return enumerator;  }Tomorrow's forecast: chances of memory leak in the afternoon.Quote:T getCurrent()Shouldn't that be a T&? Shouldn't it be a const member function.  T& getCurrent() constSimilarly, how do you plan to deal with const List objects?   ;  Hey fruny,Since you are online and you seem to know alot about STL, at least alot more then me...virtual IEnumerator<T>* GetEnumerator(){  Enumerator<T>* enumerator = new Enumerator<T>(/* innerList.begin() */);  return enumerator;}Like you said, i hate that, since this can cause alot of leaks. Is there a way of returning it by reference? I gave up on that too. My conclusion was since the base class is abstract is can't be done.Could something like a safe_pointer or something similar can same my ass with this?Thanks in advance,Jonathan   ;Quote:Original post by LowRadIs there a way of returning it by reference?No. Type erasure using the Bridge Pattern is your best bet: create an Enumerator type that holds a IEnumerator pointer and performs the virtual dispatch.Quote:Could something like a safe_pointer or something similar can same my ass with this?boost::shared_ptr would help implement the above-mentioned Enumerator.Off-hand:template<typename T> class MyEnumerator;template<typename T> class IEnumerator{public:   MyEnumerator<T> Encapsulate();   // other stuff};template<typename T> class MyEnumerator{   boost::shared_ptr< IEnumerator<T> > ptr_;private:   friend class IEnumerator<T>;   explicit MyEnumerator(IEnumerator* ptr) : ptr_(ptr)   {}public:   T& getCurrent() const   { return ptr_->getCurrent();   }   bool MoveNext()    { return ptr_->MoveNext();   }   void Reset()    { ptr_->Reset();   }};template<typename T> Enumerator<T> IEnumerator<T>::Encapsulate(){   return Enumerator<T>(this);}Then you can do:virtual MyEnumerator<T> GetEnumerator(){   IEnumerator<T>* ptr = new Enumerator<T>(/* innerList.begin() */);   return ptr->Encapsulate();}Quote:Since you are online and you seem to know alot about STL, at least alot more then me...This hasn't much to do with the STL and more to do with the language itself. [smile]   