Bonjour,
Je voudrais convertir une application Windows sous Linux et j'ai un problème avec les unions anonymes.
J'ai besoin d'avoir une classe représantant des vecteurs pour une application 3D. Les composantes des ces vecteurs sont nomées x,yz,w ou s,t,r,q ou u,v,r,q selon le contexte. Mon code ce dessous compile bien sous Windows (Visual 2005) mais pas sous Linux
Messages:
Mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 /home/greg/Projets/MGX/MGX/MGX.h:96: error: declaration of float MGXVECTOR4::<anonymous union>::<anonymous struct>::r /home/greg/Projets/MGX/MGX/MGX.h:92: error: conflicts with previous declaration float MGXVECTOR4::<anonymous union>::<anonymous struct>::r /home/greg/Projets/MGX/MGX/MGX.h:96: error: declaration of float MGXVECTOR4::<anonymous union>::<anonymous struct>::q /home/greg/Projets/MGX/MGX/MGX.h:92: error: conflicts with previous declaration float MGXVECTOR4::<anonymous union>::<anonymous struct>::q :: === Build finished: 4 errors, 0 warnings ===
Est ce que cela veuy dire que je ne peux pas utiliser plusieurs fois le même nom de variable dans une union, même si ils font partis de structures différentes ?
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 class MGXVECTOR4{ public: union { float Array[4]; struct { float x,y,z,w; }; struct { float u,v,r,q; }; struct { float s,t,r,q; }; }; explicit MGXVECTOR4() { x=0.0f;y=0.0f;z=0.0f;w=0.0f; }; explicit MGXVECTOR4( float x , float y , float z, float w ) { this->x = x; this->y = y; this->z = z;this->w = w; } inline operator float*() { return Array; } MGXVECTOR4 operator= (const MGXVECTOR4 &B) { if (this == &B) return B; this->x = B.x; this->y = B.y; this->z = B.z; this->w = B.w; return B; } ~MGXVECTOR4(){}; MGXVECTOR4 operator+ (const MGXVECTOR4 &B); MGXVECTOR4 operator- (const MGXVECTOR4 &B); float operator* (const MGXVECTOR4 &B); MGXVECTOR4 operator* (float factor); MGXVECTOR4 operator/ (float factor); };
Y a t-il une solution ?
Sachant que je n'utilise pas "float Array[4]", mais que j'en ai besoin pour être sûr de pouvoir convertir la classe en tableau de 4 float grâce à "inline operator float*()". Je pourrais renvoyer "&x", mais je suis pas sûr que les données seraient bien alignées en mémoire (x,y,z et w dans [0], [1], [2] et [3] ). On m'a dit sans certitude que ça force le compilateur à mettre x,y,z,w et ses synonymes (strq) dans le bon ordre et alignés.
Merci.
Partager