In your example, there is no need to use the struct
keyword before the next
declaration. It is usually considered a throw-back from C, where it is required. In C++, this would suffice:
struct Node{
int value;
Node *next;
};
However, if you had a member called Node
, then you would have to use struct
or class
:
struct Node{
int Node;
struct Node *next; // struct or class required here
};
You would also require struct
of class
for a declaration of a type that is not yet defined (a forward declaration). For example
struct Foo {
class Bar* bar_; // Bar defined later
};
where I used class
to show it makes no difference in this scenario.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…