使用typedef创建节点的优点是什么?

问题描述:

我一直困惑的是,为什么我们使用typedef结构节点创建节点,而同样的事情可以用结构节点可以轻松实现只...使用typedef创建节点的优点是什么?

+0

请参考此链接:http://*.com/questions/2566027/what-is-the-use-of-typedef –

+0

这是一个C的东西。两者都以C++工作。 –

+3

这个构造在C中有一些值,但在C++中很少。随意写'struct node {...};' –

这不是它做的方式。

它通常

struct node { ... }; 

typedef struct { ... } node; 
//here node is a alias for an anonymous struct or... 
typedef struct node_ { ... } node; //note the two names are different 

在C++中,这并不使任何特定的区别是:node是在任何情况下一个类型。

但它在C,其中节点是用于在第一种情况下的类型struct node(不只是节点)一个标签,只是该类型node在第二种情况下是不同的

库限定必须工作同为C和C++类型通常采用第二种形式中,以便它们可以在任何其他表达仅举node,而不是struct node,像在

node* first() { ... } 

代替

struct node* first() { ... }