Bonsoir,
Je voudrais effacer un élément dans une liste. L'élément en question est un événement et est constitué de plusieurs attributs.
Voici ma fonction Delete, qui se trouve dans la classe eventlist :
Je ne comprends pas trop l'erreur qu'il me donne : un problème avec la fonction erase, mais je sais pas quoi précisément. Je sais pas si je peux demander d'effacer un objet, comme je le fais, mais je vois pas à quoi d'autre appliquer la fontion erase...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 void eventlist::DeleteEvent(){ string nameeventtodelete; cout<<"Which name do you want to erase?\n"; cin >>nameeventtodelete; event eventobj(nameeventtodelete); for (list<event>::iterator it = mylistofevent.begin (); it != mylistofevent.end (); ++it) { if (nameeventtodelete==eventobj.getNameEvent()){ mylistofevent.erase( eventobj ); } } PrintEventList(); }
Voici mon fichier eventlist.hh :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 eventlist.cc: In member function void eventlist::DeleteEvent(): eventlist.cc:112: erreur: no matching function for call to std::list<event, std::allocator<event> >::erase(event&) /usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/bits/list.tcc:109: note: candidats sont: typename std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::erase(std::_List_iterator<_Tp>) [with _Tp = event, _Alloc = std::allocator<event>] /usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/bits/stl_list.h:1026: note: std::_List_iterator<_Tp> std::list<_Tp, _Alloc>::erase(std::_List_iterator<_Tp>, std::_List_iterator<_Tp>) [with _Tp = event, _Alloc = std::allocator<event>] make: *** [eventlist.o] Erreur 1
Et enfin event.hh
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 using namespace std; class eventlist{ private: list<event> mylistofevent; public: eventlist(); void PrintEventList(); void AddEvent(); void DeleteEvent(); void PrintEventListFile(); };
Je sais pas si tout ce code est nécessaire à la compréhension de mon problème, mais j'espère que vous vous y retrouverez !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 class event{ private : string nameevent; int eventnumber; string organiser; string departorganiser; string date; string place; public: event(); event(string); event(int, string,string,string,string,string); string getNameEvent(); int getNum(); string getNameOrganiser(); string getDepartOrganiser(); string getDate(); string getPlace(); };
Merci
Partager