Bonjour à tous,

j'ai un problème pour "caster" un pointeur, voici ce que je fais :
j'ai créé un typedef union

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;
avec
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;
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
8
 
void function(void)
{
  struct_1  *structVar;
  union_Str unionVar;
 
...
  structVar= (struct_1 *)(&unionVar);
Mais j'ai une remarque "use of old-style cast.

J'ai donc pensé mettre un "static_cast", comme ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
  structVar= static_cast<struct_1 *>(&unionVar);
Mais j'obtiens la remarque suivante "static_cast from 'union_Str *' to 'struct_1 *', which are not related by inheritance, is not allowed"

donc je ne sais pas quoi faire pour "caster", quelqu'un aurait une idée ?

Merci