如何在主函数中调用结构体中声明的函数
typedefstructsvg_render_engine{
svg_status_t(*move_to)(void*closure,doublex,doubley);//1
svg_status_t(*line_to)(void*closure,doublex,doubley);//2
svg_status_t(*curve_to)(void*closure,
doublex1,doubley1,
doublex2,doubley2,
doublex3,doubley3);//3
}svg_render_engine_t;
在头文件中声明了这样一个结构体,我想在主函数中分别定义1.2.3这3个函数,应该怎么做。求大神指点。我一起用的OC,最近才需要用C来编写,是个新手。
------解决思路----------------------
svg_render_engine_te1,*e2;
svg_status_tr;
void*closure;
doublex[3],y[3];
r=e1.move_to(closure,x[0],y[0]);
r=e2->line_to(closure,x[0],y[0]);
r=e2->curve_to(closure,x[0],y[0],x[1],y[1],x[2],y[2]);
------解决思路----------------------
是这个意思不?--->
typedefstructsvg_render_engine{
svg_status_t(*move_to)(void*closure,doublex,doubley);//1
svg_status_t(*line_to)(void*closure,doublex,doubley);//2
svg_status_t(*curve_to)(void*closure,
doublex1,doubley1,
doublex2,doubley2,
doublex3,doubley3);//3
}svg_render_engine_t;
svg_status_tmove_to(void*closure,doublex,doubley)
{
/*……*/
}
svg_status_tline_to(void*closure,doublex,doubley)
{
/*……*/
}
svg_status_tcurve_to(void*closure,
doublex1,doubley1,
doublex2,doubley2,
doublex3,doubley3)
{
/*……*/
}
intmain(void)
{
svg_render_engine_tsre={move_to,line_to,curve_to};
sre.move_to(/*……*/);
sre.line_to(/*……*/);
sre.curve_to(/*……*/);
}
如果觉得《c语言结构体主函数作用 怎么在主函数中调用结构体中声明的函数》对你有帮助,请点赞、收藏,并留下你的观点哦!