【发布时间】:2023-02-04 23:17:49
【问题描述】:
我声明了一些几何图形类型,例如:
typedef struct s_sphere{
t_tuple origin;
double radius;
} t_sphere;
typedef struct s_cylinder{
t_tuple origin;
double height;
double radius;
} t_cylinder;
typedef struct s_triangle{
t_tuple A;
t_tuple B;
t_tuple C;
} t_triangle;
etc...
现在,我想声明一个交集类型,它将包含两个双打和一个几何图形。然后我会将所有交叉点存储在一个链表中:
// I do not know what type to give to geometric_figure
typedef struct s_intersection{
double t1;
double t2;
// what_type geometric_figure;
} t_intersection;
typedef struct s_intersection_list{
t_intersection intersection;
struct s_intersection_list *next;
} t_intersection_list;
我可以使用void* geometric_figure,但我想尽可能避免使用 malloc。
有没有一种方便的方法可以在不分配 geometric_object 的情况下到达我想要的位置?
【问题讨论】:
-
您可以使用
union。
标签: c object-oriented-analysis