It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
给出以下代码:

typedef struct IntElement
{
    struct IntElement *next; // use struct IntElement
    int         data;
} IntElement;

typedef struct IntElement
{
    IntElement *next; // Use IntElement
    int         data;
} IntElement; // why I can re-use IntElement here?


我使用上面的数据结构来定义一个链表节点。


哪个更好?
为什么可以使用重复的名称(即typedef端的struct IntElement和IntElement)?

最佳答案

C ++也不是。第一个声明是旧的C语法。第二个人是意识到您在C ++中不需要它的人,然后在一行中忘记了它。 C ++这样做是这样的:

struct IntElement {
    IntElement* next;
    int data;
};

10-07 15:34