Bonjour,
J'ai fait un programme hyper simple pour voir comment une fonction retourne un vecteur ,
voici l'exemple :
Main
Classe "Essaye.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 #include <string.h> #include <stdio.h> #include <stdlib.h> #include <vector> #include "Essaye.h" using namespace std; int main() { Essaye Etud; Etud.MaFonction("Jean","Jack"); return 0; }
et le fichier "Essaye.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 #include <vector> #include <string.h> #include <iostream> using namespace std; #ifndef ESSAYE_H_ #define ESSAYE_H_ class Essaye { public: struct etudiant {string nom;string prenom;}; public: Essaye(); vector<etudiant> MaFonction(string,string); private : string monNom; string monPrenom; }; #endif /* ESSAYE_H_ */
Voici l'erreur qui m'affiche :
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 #include <string.h> #include <stdio.h> #include <stdlib.h> #include <vector> #include "Essaye.h" using namespace std; Essaye::Essaye() { monNom="nom1"; monPrenom="prenom1"; } vector<etudiant> Essaye::MaFontion(string nom,string prenom) { etudiant etud; vector<etudiant> vect; etud.nom = nom; etud.prenom = prenom; vect.push_back(etud); return vect; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Essaye.cpp:18: error: etudiant was not declared in this scope ../Essaye.cpp:18: error: template argument 1 is invalid ../Essaye.cpp:18: error: template argument 2 is invalid ../Essaye.cpp:18: error: no int Essaye::MaFontion(std::string, std::string) member function declared in class Essaye make: *** [Essaye.o] Error 1
Pourquoi cette erreur s'il vous plait ?
Merci
Partager