关于typedefstruct和struct HYPERLINK"http://zhidao.baidu.com/question/50166479.html"检举|2008-04-0401:53HYPERLINK"http://www.baidu.com/p/leaguesoft?from=zhidao"\t"_blank"leaguesoft|分类:HYPERLINK"http://zhidao.baidu.com/browse/866"C/C++|浏览58446次 请高手帮忙解释以下几种结构体定义的区别:struct{intx;inty;}test1;structtest{intx;inty;}test1;typedefstructtest{intx;inty}text1,text2;这几种方法把小弟弄得头疼,不胜感激! 还有:typestruct{intx;inty;}test1;
(1)struct{intx;inty;}test1;好,定义了结构test1,test1.x和test1.y可以在语句里用了。(2)structtest{intx;inty;}test1;好,定义了结构test1,test1.x和test1.y可以在语句里用了。与1比,省写了test(3)typedefstructtest{intx;inty;//你漏打分号,给你添上}text1,text2;只说了这种结构的(类型)别名叫text1或叫text2真正在语句里用,还要写:text1test1;然后好用test1.xtest1.y或写text2test1;然后好用test1.xtest1.y(4)typestruct{intx;inty;}test1;这个不可以。改typedef...就可以了。但也同(3)一样,还要写:test1my_st;才能用my_st.x和my_st.y |
|