Erreur d'inclusion multiple?
Salut,
J'ai trois fichiers individu.h :
Code:
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
| #ifndef IND
#define IND
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // Pour strcpy
#include <windows.h> // Pour sleep
#include <conio.h> // Pour getch()
typedef struct structPersonne {
char numSS[50];
char nom[50];
char prenom[50];
}Personne;
Personne monTab[4];
int nbPers;
char * getNumSS(Personne & P);
char * getNom(Personne & P);
char * getPrenom(Personne & P);
void setNumSS(char leNum[50], Personne & P);
void setNom(char * leNom, Personne & P);
void setPrenom(char * lePrenom , Personne & P);
Personne ajoutPers(char nom, char prenom, char numSS);
void suppPers(Personne & laPersonne);
void affPers(Personne & P);
void fpurge(FILE *fp);
#endif |
individu.cpp
Code:
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
|
#include "individu.h"
// Getters
char * getNumSS(Personne & P){
return P.numSS;
}
char * getNom(Personne & P){
return P.nom;
}
char * getPrenom(Personne & P){
return P.prenom;
}
// Setters
void setNumSS(char leNum [50] , Personne & P){
strcpy(P.numSS, leNum);
}
void setPrenom(char * lePrenom , Personne & P){
strcpy(P.numSS,lePrenom);
}
void setNom(char * leNom , Personne & P){
strcpy(P.nom, leNom);
}
// Fonctions additionnelles
Personne ajoutPers(char nom, char prenom, char numSS){
printf("Creation d'une personne\n");
Personne PersonneCree; // Personne créé
printf("\nSaisir Nom: ");
scanf("%s" , &PersonneCree.nom);
printf("\nSaisir Prenom: ");
scanf("%s" , &PersonneCree.prenom);
printf("\nSaisir numSS: ");
scanf("%s" , &PersonneCree.numSS);
return PersonneCree; // On retourne cette personne, elle sera mise a la case nbPers
}
void suppPers(Personne & laPersonne){
// Simulation d'attente :)
printf("\n\nSuppresion en cours ");
Sleep(1000);
printf(" .");
Sleep(1000);
printf(" .");
Sleep(1000);
printf(" .");
Sleep(1000);
// On met les champ à vide
strcpy(laPersonne.nom, "");
strcpy(laPersonne.prenom, "");
strcpy(laPersonne.numSS, "");
//nbPers--;
}
void affPers(Personne & P){ // Consulter les données d'une personne
system("CLS");
printf("Nom : %s \n", P.nom);
printf("Prenom : %s \n", P.prenom);
printf("Num Secu : %s \n\n", P.numSS);
system("pause");
}
void fpurge(FILE *fp){
int c;
while ((c = fgetc(fp)) != '\n' && c != EOF){
}
} |
et main.cpp
Code:
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
|
/*----------------------------------- Individu V 0.1 -----------------------------------*/
#include "individu.h"
char choix= ' ';
int saisie = 0;
int i;
int main(){
do{ // Tant que l'on choisi pas l'option 4
system("CLS"); // Clear Screen
printf("___ Chevalier 1.0 ___\n\n1. Ajouter une Personne \n2. Supprimer une personne \n3. Lister les personnes\n4. Quitter\n\n");
scanf("%c", &choix);
system("CLS"); // Clear Screen
switch (choix) {
case '1' :
break;
case '2' :
break;
case '3' :
system("CLS"); // Clear Screen
break;
case '4' :
break;
default:
printf("\nChoix non valide !\n");
getch();
} // Fin du switch
fpurge(stdin); // Correction d'un bug de scanf
}while (choix != 4); // Fin tant que
//Fin du prog
printf ("---------- Fin du programme ----------\n\n") ;
system("pause");
return 0;
} |
Lors de l'edition des liens j'ai l'erreur suivante :
Code:
1 2 3 4
|
1>main.obj : error LNK2005: "int nbPers" (?nbPers@@3HA) déjà défini(e) dans individu.obj
1>main.obj : error LNK2005: "struct structPersonne * monTab" (?monTab@@3PAUstructPersonne@@A) déjà défini(e) dans individu.obj
1>C:\Users\Keweed\Documents\Visual Studio 2008\Projects\individu\Debug\individu-bug.exe : fatal error LNK1169: un ou plusieurs symboles définis à différentes reprises ont été rencontrés |
On dirai un problème d'édition de liens du à l'inclusion multiple de individu.h, pourtant j'ai bien mis les #ifndef et #endif. Je ne comprend pas pourquoi j'ai toujours cette erreur.
PS : je sais que le code n'est pas propre d'ailleur il n'est pas de moi mais ce que j'aimerai savoir c'est d'ou viens l'erreur.
Merci d'avance