Bonsoir tout le monde,
j'ai un probleme sur lequel je m'arrache les cheveux desesperement!
J'ai cette erreur dont je n'arrive pas a me debarasser et que je ne comprends absolument pas!
multiple definition of operator<<(std::ostream &,enseignantcherch&);
But: je veux afficher une instance de enseignantcherch avec <<;
Voila mon code:
fichier .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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 #include <iostream> #include <string> using namespace std; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT */ /* */ /*----------------------------------------------------------------------------*/ class enseignant { private: string nom; string prenom; string matiere1; string tel; static int nb; public: enseignant(string n, string p, string mat, string t); ~enseignant(); string get_nom(); string get_prenom(); string get_matiere(); string get_tel(); void inc_nb(); void dec_nb(); int get_nb(); virtual void affiche(ostream & f)=0; }; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT TEMPS PLEIN */ /* */ /*----------------------------------------------------------------------------*/ class enseignantTC:public enseignant { private: string matiere2; public: enseignantTC(string n, string p, string mat, string t, string mat2); ~enseignantTC(); string get_matiere2(); void affiche(ostream & f); }; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT CHERCHEUR */ /* */ /*----------------------------------------------------------------------------*/ class enseignantcherch:public enseignant { private: string pole; public: enseignantcherch(string n, string p, string mat, string t, string pole); ~enseignantcherch(); string get_pole(); void affiche(ostream & f); friend ostream & operator <<(ostream & sortie,enseignantcherch & t); }; /*----------------------------------------------------------------------------*/ /* */ /* SURCHARGE DEE LOPERATEUR << */ /* */ /*----------------------------------------------------------------------------*/ ostream & operator <<(ostream & sortie,enseignantcherch & t) { t.affiche(sortie); return sortie; };
fichier .cpp (definition)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 #include <iostream> #include <string> #include "enseignant.h" using namespace std; int enseignant::nb=0; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT */ /* */ /*----------------------------------------------------------------------------*/ /*---constructeur---*/ enseignant::enseignant(string n, string p, string mat, string t):nom(n),prenom(p),matiere1(mat),tel(t) { cout<<"Creat. enseignant abstrait: "<<this<<endl; }; /*---destructeur---*/ enseignant::~enseignant() { cout<<"Destruct. enseignant: "<<this<<endl; }; /*---accesseur---*/ string enseignant::get_nom(){return nom;}; string enseignant::get_prenom(){return prenom;}; string enseignant::get_matiere(){return matiere1;}; string enseignant::get_tel(){return tel;}; int enseignant::get_nb(){return nb;}; void enseignant::inc_nb(){nb++;}; void enseignant::dec_nb(){nb--;}; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT TEMPS PLEIN */ /* */ /*----------------------------------------------------------------------------*/ /*---constructeur---*/ enseignantTC::enseignantTC(string n, string p, string mat, string t, string mat2):enseignant(n,p,mat,t),matiere2(mat2) { cout<<"Creat. enseignantTC: "<<this<<endl; inc_nb(); }; /*---destructeur---*/ enseignantTC::~enseignantTC() { cout<<"Destruct. enseignantTC: "<<this<<endl; dec_nb(); }; /*---accesseur---*/ string enseignantTC::get_matiere2(){return matiere2;}; /*---affichage---*/ void enseignantTC::affiche(ostream & f) { f<<"========== EnseignantTC: "<<endl; f<<"nom: "<<get_nom()<<", prenom:"<<get_prenom()<<endl; f<<"tel: "<<get_tel()<<endl; f<<"matiere1: "<<get_matiere()<<", matiere2: "<<matiere2<<endl; f<<"========================"<<endl; }; /*----------------------------------------------------------------------------*/ /* */ /* DEFINITION DE LA CLASSE ENSEIGNANT CHERCHEUR */ /* */ /*----------------------------------------------------------------------------*/ /*---constructeur---*/ enseignantcherch::enseignantcherch(string n, string p, string mat, string t, string pole):enseignant(n,p,mat,t),pole(pole) { cout<<"Creat. enseignantcherch: "<<this<<endl; inc_nb(); }; /*---destructeur---*/ enseignantcherch::~enseignantcherch() { cout<<"Destruct. enseignantTC: "<<this<<endl; dec_nb(); }; /*---accesseur---*/ string enseignantcherch::get_pole(){return pole;}; /*---affichage---*/ void enseignantcherch::affiche(ostream & f) { f<<"========== Enseignant_Chercheur: "<<endl; f<<"nom: "<<get_nom()<<", prenom:"<<get_prenom()<<endl; f<<"tel: "<<get_tel()<<endl; f<<"matiere1: "<<get_matiere()<<", pole: "<<pole<<endl; f<<"========================"<<endl; };
et mon main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 #include <iostream> #include <string> #include "enseignant.h" using namespace std; int main() { enseignantcherch t2("toto","albert","physique","06-00-00-21-02","anglais"); cout<<t2; system("pause"); };
Svp help me please j'ai presque pu de cheveux!![]()
Merci a tous par avance!!![]()
Partager