std::list d'une class Template
Bonjour a tous,
Dans le cadre de mes etudes je suis bloque sur un exercice, je n'arrive pas a compiler un bete code utilisant les templates.
L'exo consiste a refaire une multimap perso.
J'ai donc une classe Pair comme suit :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
template <typename K, typename V> class Pair {
public:
Pair(K &k, V &v) : _key(k), _value(v) {
}
Pair(const Pair<K, V> &p) {
*this = p;
}
Pair & operator=(const Pair &p) {
if (this != &p) {
_key = p._key;
_value = p._value;
}
return (*this);
}
K& getKey() const {
return _key;
}
V& getValue() const {
return _value;
}
private:
K &_key;
V &_value;
}; |
Mon soucis vien quan je cherche a declarer un std::list de Pair.
Je pensais avoir resolu le probleme en declarant un typedef :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
template <typename K, typename V>class Multimap {
public:
typedef std::list<Pair<V, K> > listType; /* Mon typedef */
private:
listType _list; /* Ma list */
listType &getElemsByKey(const K& key) {
listType::iterator it = _list.begin(); /* ERREUR DE COMPILE ICI */
}
}; |
J'ai une grosse erreur sur cette ligne :
Citation:
./ex_4/ex_4.hpp: In member function `std::list<Pair<V, K>, std::allocator<Pair<V, K> > >& Multimap<K, V>::getElemsByKey(const K&)':
In file included from ./ex_4/main.cpp:3:
./ex_4/ex_4.hpp:80: error: expected `;' before "it"
Mon compilateur g++ version 3.4.4
Merci d'avance :ccool: