Bonjour,
voila je vous expose mon probl�me.
J'ai une classe Personnel dont h�rite Employe, une classe Session avec un vector<Personnel> pers et une classe Formation avec un vector<Session> sess.
Dans ma fonction inscrireParticipant, je remplis le vector pers avec des objets Personnel.
Le programme tourne, malheureusement, lorsque j'utilise cette fonction et que j'affiche une Formation, le vector pers de la Session est bien rempli mais pas celui de la Formation .
Auriez-vous une id�e? si du moins vous avez compris mon probleme. Merci � vous.
- Formation.cpp -
- Session.h -
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 #include <iostream> using namespace std; #include "Formation.h" Formation::Formation(int num, char name[], int jours, char tel[]) { numero = num; strcpy(nom,name); nb_jours = jours; strcpy(telephone,tel); } Formation Formation::operator =(const Formation &obj) { numero = obj.numero; strcpy(nom,obj.nom); nb_jours = obj.nb_jours; strcpy(telephone,obj.telephone); return *this; } void Formation::afficher() { cout<<" "<<endl; cout<<" Numero: "<<numero<<endl; cout<<" Nom : "<<nom<<endl; cout<<" Jours : "<<nb_jours<<endl; cout<<" Tel. : "<<telephone<<endl; cout<<" "<<endl; cout<<" - liste des sessions -"<<endl; cout<<" ------------------"<<endl; if (liste.empty()) { cout<<" Il n'y a pas de session pour cette formation."<<endl; } else { for (int i=0; i<liste.size(); i++) { liste[i].afficher(); } } cout<<" ------------------"<<endl; } void Formation::ajouterSession(const Session &sess) { liste.push_back(sess); } void Formation::supprimerSession(int pos) { liste.erase(liste.begin()+(pos-1)); }
- Session.cpp -
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
24
25
26
27
28
29
30
31
32 #ifndef H_SESSIONS #define H_SESSIONS #include "Employe.h" #include <vector> #include <iostream> using namespace std; class Session { private: char date[9]; char lieu[20]; float prix; vector<Personnel> liste; public: Session::Session(char dat[], char place[], float tarif) { strcpy(date, dat); strcpy(lieu,place); prix = tarif; }; ~Session(){}; void afficher(); Session operator=(const Session &obj); void inscrireParticipant(const Personnel& pers); }; #endif
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #include <iostream> using namespace std; #include "Session.h" void Session::afficher() { cout<<" Date : "<<date<<endl; cout<<" Lieu : "<<lieu<<endl; cout<<" Tarif : "<<prix<<endl; cout<<""<<endl; cout<<" - participants -"<<endl; cout<<" ------------"<<endl; if(liste.empty()) { cout<<" Il n'y a pas de participant inscrit a cette session."<<endl; } else { for (int i=0; i<liste.size(); i++) { liste[i].afficher(); } } cout<<" ------------"<<endl; } Session Session::operator =(const Session &obj) { strcpy(date, obj.date); strcpy(lieu,obj.lieu); prix = obj.prix; return *this; } void Session::inscrireParticipant(const Personnel& pers) { cout<<"---- INSCRIPTION PARTICIPANT PAR REFERENCE -----"<<endl; liste.push_back(pers); }
-main- --> je vous montre ou ca foire ici.
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
24
25
26
27 void main() { Responsable_formation resp(3,"bill","boll", "rue Sare 12, 4000 Liege"); Employe emp1(1,"Crommen", "Jonathan", "rue Sauny 13, 4624 Romsee", "0498733855", "[email protected]", "programmeur Java"); Employe *emp2 = new Employe(2,"Melotte", "Amandine", "rue Franck 33, 4623 Magn�e", "0498712343", "[email protected]", "analyste"); Formation form1(1, "SQL SERVER 2008", 4, "043551212"); Formation form2(3, "COBOL", 2); Session sess1("23/06/09", "Forem Liege", 1240); Session sess2("10/09/09", "Bruxelles expo", 4240); Session sess3("02/02/10", "Forem Namur", 2340); form1.ajouterSession(sess1); ---> marche sans probleme form1.ajouterSession(sess2); sess1.inscrireParticipant(emp1); ---> le probleme est ici form1.afficher(); --> si j'affiche ceci, il n'y a pas de participant dans la session de la formation par contre si je refais un form1.ajouterSession, ca marche, y aurait-il un probleme de reference?? getchar(); }
Merci pour votre lecture!
Partager