typedef语法规则其实简单句来说定义对象语法前加关键字typedef剩下变原本定义对象标识符换成类型标识符对应语义从定义对象改成定义类型别名typedef看起来复杂根本原因对象定义语法比较复杂例分隔符*和[]用法 typedef struct node{ datatype data; struct node *lchild,*rchild; }bintnode; 对应对象定义: struct node{ datatype data; struct node *lchild,*rchild; }bintnode; 去除bintnode来看类型struct node完整描述加上了bintnode来看表示定义了struct node类型对象bintnode 现前面有typedef因此bintnode对象名而类型名也定义了类型别名bitnode实际上指struct node完整类型 typedef定义类型别名作用域内和被定义原类型语义上等价都表示同类型名称里typedef之bitnode和struct node互相代替(注意C++同命名空间内类型名和对象名没有重复struct省略struct node等价于node) 更复杂点: struct node{ datatype data; struct node *lchild,*rchild; }bintnode, *bintree; 注意定义对象时*修饰对象本身而修饰类型因此里定义了struct node对象bintnode和struct node*类型对象bintree 对应类型定义: struct node{ datatype data; struct node *lchild,*rchild; }bintnode, *bintree; 里定义了类型别名bintnode表示完整类型struct node及bintree表示类型struct node* 拆开来成了 typedef struct node{ datatype data; struct node *lchild,*rchild; }bintnode; typedef bintnode *bintree; 种写法看起来应该稍微清楚了点 至于下面cirqueue和上面bintnode类似只里省略了结构体名称匿名类型样写主要好处类型名省略struct(C++里面样写也省略) ====
typedef
最新推荐文章于 2019-08-19 09:51:44 发布