-5
我一直在研究这段代码,并且遇到了一个段错误。我几乎肯定它来自于我如何在OBJ_T类型中初始化我的功能点。下面是我有:函数指针在c中的typedef结构中
typedef struct obj
{
COLOR_T color;
int (*intersect)(RAY_T ray, struct obj, VP_T *int_pt, VP_T *normal, double *t);
union geom
{
SPHERE_T sphere;
PLANE_T plane;
}geom;
} OBJ_T;
这是该行我得到的赛格故障:
if((*(objs[i].intersect))(ray, objs[i], &int_pt, &normal, &t) == 1)
那么..你如何初始化它? –
你可以打印任何这些值(包括func ptr)来检查“明显不良”(如空指针)看起来你应该做一些很好的旧调试... – John3136