I have a struct that contain an attribute that can take many types, I want ask about the most appropriate way to declare this attribute.
Example:
struct
{
void* pShape; //poiter to the shape that will be casted on *tCircle or *tRectangle
int type;//type of the shape
int h;
int l;
}tImage;
struct{
int size;
int r;
HANDLE calcul;
}tCircle
struct{
int size;
int x;
int y;
HANDLE calcul;
}tRectangle;
As you see here i'am using void* to declare a pointer to the shape and use type attribute to guess the type of the shape.
this is my function for the calcuation of the size of the shape in an image
int Image_Get_ShapeSize(tImage Im)
{
switch (Im.type)
{
case CIRCLE:
((tCircle*)(Im.shape))->calcul();
break;
case RECTANGLE:
((tRectangle*)(Im.shape))->calcul();
break;
default:
break;
}
}
what do you think about this is it a good method ?