Kann Element nicht aus Vektor löschen



  • Hallo,

    ich bräuchte mal kurz Hilfe.
    Ich hab eine Template-Klasse:

    template< typename T >
    class Foo
    {
       private:
          std::vector<T*> elemente;
    
       public:
          bool deleteElement( size_t id )
          {
             if( id >= this->elemente.size() )
                return false;
    
             std::vector<T*>::iterator it = this->elemente.begin() + id; //Zeile 188
             this->elemente.erase( it );
             return true;
          }
    };
    

    Wenn ich kompilieren will kommt folgende Meldung die ich nicht verstehe:
    `In member function ‘bool Foo<T>::deleteElement(size_t)’:

    188 error: expected ‘;’ before ‘it’

    189 error: ‘it’ was not declared in this scope

    ||=== Build finished: 2 errors, 0 warnings ===|`

    Was hat das zu bedeuten? Was ist an den zwei Zeilen falsch? Ich will doch nur ein Element aus dem Vektor löschen...

    MfG. Ich


  • Mod

    typename std::vector<T*>::iterator it = this->elemente.begin() + id;
    

    Hintergrund zur Problematik:
    http://pages.cs.wisc.edu/~driscoll/typename.html


Anmelden zum Antworten