Bonjour
Je coince sur un problème tout bête.
J'ai défini dans un fichier.h un certain nombre de structures avec des fonctions amies :
J'ai, comme il se doit, encadré ces déclarations par un #ifndef et un #endif.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 #ifndef M_PI_2 #define M_PI_2 1.57079632679489661923 #endif #ifndef H2D_H #define H2D_H typedef struct h2Dvector { double x, y, t; h2Dvector () : x(0), y(0), t(0) {}; h2Dvector (double a, double b, double c) : x(a), y(b), t(c) {}; // binary operators friend h2Dvector operator + ( const h2Dvector&, const h2Dvector&); friend h2Dvector operator - ( const h2Dvector&, const h2Dvector&); friend h2Dvector operator * ( double, const h2Dvector& ); friend h2Dvector operator * ( const h2Dvector&, const h2Dmatrix&); } h2Dpoint, h2Dvector, *p2Dpoint, *p2Dvector; h2Dvector operator + ( const h2Dvector& V1, const h2Dvector& V2) { h2Dvector V; V.x = V1.x + V2.x; V.y = V1.y + V2.y; if ((V1.t > 0) || (V2.t > 0)) V.t = 1; else V.t = 0; return V; } (et coetera...) #endif
Lorsque je fais une fois appel à ce fichier .h, tout se passe bien. Je compile et ça s'exécute comme il faut.
entête hTopo.h :
fichier hTopo.cpp :Code:
1
2
3
4
5
6
7
8
9 #ifndef HTOPO_H #define HTOPO_H #include "h2D.h" // le fichier d'entête ci-dessus (etc...) #endif
Si maintenant j'ajoute un autre fichier faisant appel à ce fichier hTopo, patatras, ça ne marche plus !Code:
1
2
3
4 #include "htopo.h" (etc...)
entête autrefichier.h :
fichier autrefichier.cpp :Code:
1
2
3
4
5
6
7
8
9 #ifndef OFICHIER_H #define OFICHIER_H #include "hTopo.h" // le fichier d'entête ci-dessus (etc...) #endif
Je me retrouve avec une erreur LNK2005 de redéfinition de structire et de fonctions :Code:
1
2
3
4 #include "autrefichier.h" (etc...)
Quelqu'un a-t'il une idée qui pourrait m'aider ?Code:
1
2 hTopo.obj : error LNK2005: "struct h2Dvector __cdecl operator+(struct h2Dvector const &,struct h2Dvector const &)" (??H@YA?AUh2Dvector@@ABU0@0@Z) déjà défini(e) dans autrefichier.obj
Merci par avance.