-3

Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?

I have a template class like below

  template <class Key, class Object>
  class  TObjectRegistery
  {
  public:
     typedef map<const Key,  Object*> ObjectMap;

     void AddObject(Object *obj){
        objectMap_[obj.code()] = obj;
     }
  private:
     ObjectMap  objectMap_;
     }

I want to run an iteration outside of TFactory, then I want to add two member functions to the class.

  ObjectMap::iterator xbegin(){
     return objectMap_.begin();
  }

but I get an error that I'm missing ; before xbegin like undefine ObjectMap::iterator

  "missing ';' before identifier 'xbegin'"

why does this happen? how I can fix it ? if this good way to do iteration out of class?

Community
  • 1
  • 1
herzl shemuelian
  • 3,346
  • 8
  • 34
  • 49

1 Answers1

5

You also need the typename keyword before ObjectMap, since it's derived type of the template parameters:

typename ObjectMap::iterator xbegin(){
    return objectMap_.begin();
}
Andrés Senac
  • 841
  • 6
  • 14