障碍物[0] .x = 0; 障碍物[0] .y = 0; 障碍物[0] .width =(OFFSET_X * 2 ); 障碍[0] .height =(OFFSET_Y * 2); int main(无效) { 返回0; } / *结束代码* / 解决方案 Ian Tuomi< ia*@co.jyu.fi>这样说: 障碍BB障碍[1]; 障碍物[0] .x = 0; 障碍物[0] .y = 0; 障碍物[0] .width =(OFFSET_X * 2); 障碍物[0 ] .height =(OFFSET_Y * 2); 障碍物是一个指向结构的指针(这就是你声明一个 $时得到的结果) b $ b数组),所以要访问元素,你想做障碍[0] - > x等等。 - Christopher Benson -Manica | Jumonji giri,荣誉。 ataru(at)cyberspace.org | Christopher Benson-Manica写道: Ian Tuomi< ia*@co.jyu.fi>这样说: 障碍物障碍物[1]; 障碍物[0]。 x = 0; 障碍物[0] .y = 0; 障碍物[0] .width =(OFFSET_X * 2); 障碍物[0]。高度=(OFFSET_Y * 2) ; 障碍是指向结构的指针(这是你声明一个数组时得到的),所以要访问元素,你想要做障碍[ 0] - > x等 哦当然!非常感谢你! Ian Tuomi写道: Christopher Benson-Manica写道: Ian Tuomi< ia*@co.jyu.fi>这样说: 障碍物障碍物[1]; 障碍物[0] .x = 0; 障碍物[0] .y = 0; 障碍物[0] .width =(OFFSET_X * 2); 障碍物[0] .height =(OFFSET_Y * 2); 障碍是一个指向结构的指针(这是你在声明一个数组时得到的),所以要访问元素,你想做障碍[ 0] - > x等 哦当然!非常感谢! 嗯..对不起我得出了结论,但现在它说: 之前解析错误 - > ;''标记'所以看起来我或者仍然有一个问题或者错误的介绍你的消息非常糟糕。 Could anyone please tell me what is wrong with this code? Compiler erroris: "parse error before ''.'' token" in lines 13-16. I tried searching theinternet but all the reference guides etc. say It''s ok. Is it a problemwith the compiler? I am using the dev-c++ front-end for mingw. /* start code */#include <stdio.h> typedef struct{int x;int y;int width;int height;}ObstacleBB; ObstacleBB obstacles[1]; obstacles[0].x = 0;obstacles[0].y = 0;obstacles[0].width = (OFFSET_X * 2);obstacles[0].height = (OFFSET_Y * 2); int main(void){return 0;}/* end code */ 解决方案 Ian Tuomi <ia*@co.jyu.fi> spoke thus: ObstacleBB obstacles[1]; obstacles[0].x = 0; obstacles[0].y = 0; obstacles[0].width = (OFFSET_X * 2); obstacles[0].height = (OFFSET_Y * 2); obstacles is a pointer to a struct (that''s what you get when you declare anarray), so to access elements, you want to do obstacles[0]->x, etc. --Christopher Benson-Manica | Jumonji giri, for honour.ataru(at)cyberspace.org |Christopher Benson-Manica wrote: Ian Tuomi <ia*@co.jyu.fi> spoke thus:ObstacleBB obstacles[1];obstacles[0].x = 0;obstacles[0].y = 0;obstacles[0].width = (OFFSET_X * 2);obstacles[0].height = (OFFSET_Y * 2); obstacles is a pointer to a struct (that''s what you get when you declare an array), so to access elements, you want to do obstacles[0]->x, etc. Oh ofcourse! Thankyou so much! Ian Tuomi wrote: Christopher Benson-Manica wrote: Ian Tuomi <ia*@co.jyu.fi> spoke thus: ObstacleBB obstacles[1]; obstacles[0].x = 0; obstacles[0].y = 0; obstacles[0].width = (OFFSET_X * 2); obstacles[0].height = (OFFSET_Y * 2); obstacles is a pointer to a struct (that''s what you get when you declare an array), so to access elements, you want to do obstacles[0]->x, etc. Oh ofcourse! Thankyou so much! Umh.. sorry I jumped into conclusions but now it says:"parse error before ''->'' token" so looks like I either still have aproblem or mis-interperted youre message really badly. 这篇关于结构数组的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 01:57