Bonjour à tous.
Je me suis lancé a faire un petit programme pour apprendre a me servir des map.
J'ai
essayé aussi de faire des fonctions template pour afficher et supprimer
la map mais j'ai des erreurs de compilation que je ne comprend pas .
Je suis sur linux.
Voici le code :
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef map<int, string> MaMap;
void addMap( MaMap*, int ,string );
template <class X, class T>
void printMap( map<X, T*>* & );
template <class X, class T>
void clean( map<X, T*>* & );
int main( int argc, char** argv )
{
if( argc <= 1 )
{
cout << "Arguments?" << endl;
return 1;
}
MaMap* myMap = new MaMap;
for( int i = 0; i < argc; i++ )
{
addMap( myMap, i, argv[i] );
}
printMap( myMap );
clean( myMap );
return 0;
}
void addMap(MaMap* m, int i, string s )
{
pair<MaMap::iterator, bool>res = m->insert( MaMap::value_type( i, s ));
if( res.second == false )
{
cout << "Probleme ajout map" << endl;
}
}
template <class X, class T>
void printMap( map<X,T>* &m )
{
if( m == NULL )
return;
for( map<X,T>::iterator i = m->begin() ; i != m->end() ; i++ )
{
cout << (*i).first << "\t" << (*i).second << endl;
}
}
template <class X, class T>
void clean(map<X, T>* &theMap)
{
if( theMap == NULL )
return;
for( map<X, T>::iterator i = theMap->begin() ; i != theMap->end() ; i++ )
{
if( (*i).second == NULL )
continue;
delete (*i).second;
(*i).second = NULL;
}
theMap->clear();
delete theMap;
theMap = NULL;
}
Et voici la compil :
main.cpp: In function «int main(int, char**)":
main.cpp:28: erreur: no matching function for call to «printMap(MaMap*&)"
main.cpp:29: erreur: no matching function for call to «clean(MaMap*&)"
main.cpp: In function «void printMap(std::map<X, T, std::less<_Key>, std::allocator<std::pair<const _Key, _Tp> > >*&)":
main.cpp:49: erreur: expected `;' before «i"
main.cpp:49: erreur: «i" was not declared in this scope
main.cpp: In function «void clean(std::map<X, T, std::less<_Key>, std::allocator<std::pair<const _Key, _Tp> > >*&)":
main.cpp:60: erreur: expected `;' before «i"
main.cpp:60: erreur: «i" was not declared in this scope
make: *** [main.o] Erreur 1
Quelqu'un à une idée sur mon problème?
Je vous remercie d'avance
Cordialement
Sebome
Sébome
