View Single Post
Old 21-05-2007, 13:56   #2
marco.r
Senior Member
 
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
Quote:
Originariamente inviato da Vecchia Spugna Guarda i messaggi
Salve ragazzi

facendo una cosa del genere

template <class T> T *cercaPerId(unsigned ident, set<T *> &tabella)
{
set <T *>::iterator it;
.....
}

il compilatore mi dice che vuole il punto e virgola prima di it, che è un modo come un altro per dirmi non so che dirti ma a me questa cosa non mi va bene.
Quello che sta cercando di dire il compilatore, e' che non riesce a capire cosa sia set<T*>::iterator. Nel caso generale e' un nome di tipo, ma nulla vieta di ridefinire iterator in una specializzazione come valore:
Codice:
#include <set>
#include <iostream>


struct Foo
{
  int foo;
};

namespace std
{
  template <>
  class set<Foo>
  {
  public:
    static int iterator;
  };
}

int std::set<Foo>::iterator = 10;

using namespace std;

int main()
{
  set<Foo>::iterator = 5;
  cout << set<Foo>::iterator << endl;
}

Nel tuo caso, devi dire esplicitamente al compilatore che si tratta del nome di un tipo, per cui il tuo codice va modificato come segue
Codice:
template <class T> T *cercaPerId(unsigned ident, set<T *> &tabella)
{
  typename set <T *>::iterator it;
.....
}
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele
marco.r è offline   Rispondi citando il messaggio o parte di esso