Bonjour à tous,
j'ai un problème pour "caster" un pointeur, voici ce que je fais :
j'ai créé un typedef union
avec
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 typedef union { struct_1 str1; struct_2 str2; struct_3 str3; }union_Str;
Dans une fonction je déclare un pointeur et une variable:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 typedef struct { float f1; float f2; ... } struct_1;
Mais j'ai une remarque "use of old-style cast.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 void function(void) { struct_1 *structVar; union_Str unionVar; ... structVar= (struct_1 *)(&unionVar);
J'ai donc pensé mettre un "static_cast", comme ceci
Mais j'obtiens la remarque suivante "static_cast from 'union_Str *' to 'struct_1 *', which are not related by inheritance, is not allowed"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 structVar= static_cast<struct_1 *>(&unionVar);
donc je ne sais pas quoi faire pour "caster", quelqu'un aurait une idée ?
Merci
Partager