Bonsoir
je viens de commencer le c++ il y a a peu pr�s une semaine mais la je suis completement coinc� avec l'appel d'un constructeur dans une classe qui s'appelle 'Mammifere' qui normalement herite de la class 'Animal'ce qui m'agace le plus c'est qu'il y a une autre classe 'Oiseau' qui marche ss souci !!voila le .h des classes
'Mammifere' :
Classe 'Animal' :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <string> #include "Animal.h" class Mammifere: public Animal{ protected : double duree; public : Mammifere(); Mammifere(std::string nom,std::string couleur,std::string cri,double dure); virtual void affiche() const; void setDuree(double d); };
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 #include <string> class Animal{ protected : std::string cri,couleur,nom; public : Animal(); Animal(std::string nom,std::string couleur,std::string cri); virtual void affiche()const ; void setCri(std::string cri); void setNom(std::string nom); void setCouleur(std::string couleur); };
voila le main :
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
91
92
93
94 #include <iostream> #include <string> #include <vector> #include "Animal.h" #include <time.h> #include "Oiseau.h" #include "Mammifere.h" using namespace std; void getAnimal(int choix,Animal* a){ if(choix<4 && choix>0){ string nom,cri,couleur; do{ cout<<"Entrez le nom :"; getline(cin,nom); }while(nom.length()==0); a->setNom(nom); do{ cout<<"Entrez le cri :"; getline(cin,cri); }while(cri.length()==0); a->setCri(cri); do{ cout<<"Entrez la couleur :"; getline(cin,couleur); }while(couleur.length()==0); a->setCouleur(couleur); switch (choix) { case 2: { double d; do{ cout<<"Entrez la dur�e de sevrage :"; cin>>d; }while(d<0); a=0; Mammifere ma(nom,couleur,cri,d);// ligne qui pose probleme !! a=&ma; break; } case 3: { double l; do{ cout<<"Entrez la longueur des ailes :"; cin>>l; }while(l<0); a=0; Oiseau o(nom,couleur,cri,l); a=&o; break; } } } } void affich(Animal const& a){ a.affiche(); } int main() { vector<Animal*> Arche; int n; do{ cout<<"Entrez le nb d'animaux : "; cin>>n; }while(n<1); for(int i=0;i<n;i++){ int choix=0; do{ cout<<"�a sera : 1-Animal\n2-Mammifere\n3-Oiseaux" <<"\nFaites un choix : "; cin>>choix; }while(choix<1 || choix>3); Arche.push_back(new Animal()); getAnimal(choix,Arche[i]); } for(int i=0;i<n;i++){ affich(*(Arche[i])); delete Arche[i]; Arche[i]=0; } return 0; }
code d'erreur complet :
obj\Debug\main.o||In function `Z9getAnimaliP6Animal'
|44|undefined reference to `Mammifere::Mammifere(std::string, std::string, std::string, double)'|
obj\Debug\main.o||In function `~Mammifere'
|7|undefined reference to `vtable for Mammifere'|
||=== Build finished: 2 errors, 0 warnings ===|
donc le probleme reside dans l'appel de la class Mammifere
Partager