使用typedef创建节点的优点是什么?
答
这不是它做的方式。
它通常
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() { ... }
请参考此链接:http://*.com/questions/2566027/what-is-the-use-of-typedef –
这是一个C的东西。两者都以C++工作。 –
这个构造在C中有一些值,但在C++中很少。随意写'struct node {...};' –