在typedef结构中定义struct [英] Defining struct within typedef struct

查看:188
本文介绍了在typedef结构中定义struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typedef struct leaf{
  int value;
  struct leaf* lchild;
  struct leaf* rchild;
} LEAF;

例如上面的一个定义结构 leaf 并使该类型的2个成员:lchild,rchild。这是一个递归?

For example the one above defines structure leaf and makes 2 members of that type: lchild, rchild. So is this like a recursion?

推荐答案

你的假设是错误的。 leaf 有2个类型 leaf * 的成员,而不是 leaf 。所以它不是(数据)递归。

Your assumption is wrong. leaf has 2 members of type leaf*, not leaf. So it's not (data) recursion.

和以下

struct leaf
{
    leaf x;
};

在C ++中是非法的。注意,在C ++中,当你声明该类型的变量的成员时,你不需要 struct leaf ,你也不需要 typedef

would be illegal in C++. Note that in C++ you don't need struct leaf when you declare a member of variable of that type, nor do you need the typedef.

这篇关于在typedef结构中定义struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆