-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