免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5710 | 回复: 5
打印 上一主题 下一主题

struct 循环嵌套 什么原理? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-02 12:50 |只看该作者 |倒序浏览

  1. typedef int Tsymbol;
  2. struct Tsquare;
  3. typedef Tsquare *Psquare;

  4. struct Tprior
  5. {
  6.   int pv,ps[4];  //evaluation in 4 directions and sum
  7.   int i;         //in which linked list
  8.   Psquare nxt,*pre;//linked list pointers
  9. };

  10. struct Tsquare                  
  11. {
  12.   Tsymbol z;   //0=nothing, 1=my, 2=opponent, 3=outside
  13.   Tprior h[2]; //evaluation for both players
  14.   short x,y;   //coordinates 0..width-1, 0..height-1
  15.   Psquare *inWinMoves; //pointer to winMoves1 array
  16. };
复制代码


Tprior 里面包含了 Psquare ,Psquare 是 Tsquare的指针,Tsquare里面又包含了Tprior ,这不成死循环了么?
Tsquare里有Psquare ,Psquare 是 Tsquare的指针,又是死循环?

彻底晕了

C下编译不过去
C++下可以
哪位讲讲,C++是怎么理解的

[ 本帖最后由 NetSpider 于 2007-11-2 12:52 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-11-02 12:58 |只看该作者
原帖由 NetSpider 于 2007-11-1 20:50 发表

typedef int Tsymbol;
struct Tsquare;
typedef Tsquare *Psquare;

struct Tprior
{
  int pv,ps[4];  //evaluation in 4 directions and sum
  int i;         //in which linked list
  Psquare n ...


结构体中只是包含了另外结构体的指针,大小事确定的,当然没问题。不然链表怎么实现?

论坛徽章:
0
3 [报告]
发表于 2007-11-02 13:07 |只看该作者
但是
在C下编译不过去

是不是C要求struct中用的struct必须事先定义?

论坛徽章:
0
4 [报告]
发表于 2007-11-02 13:09 |只看该作者
那段代码是一个C++程序中的

用C有办法解决么

论坛徽章:
0
5 [报告]
发表于 2007-11-02 13:16 |只看该作者
[quote]原帖由 [i]NetSpider[/i] 于 2007-11-1 21:07 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=7543529&ptid=1010722][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
但是
在C下编译不过去

是不是C要求struct中用的struct必须事先定义? [/quote]

加上 "struct" 关键字:
struct Tprior h[2];

论坛徽章:
0
6 [报告]
发表于 2007-11-02 13:28 |只看该作者

谢谢
回去了试试

公司没编译器
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP