Can I name a variable with the same name as a typedef'd structure name?

后端 未结 5 1066
北荒
北荒 2020-12-20 14:14

Here is the structure declare code.

struct list_el {
    int val;
    struct list_el * next;
};

typedef struct list_el item;

And when I

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 15:02

    Jonathan Leffler answered you your question.

    I just want to add: if you write your code in c++, you don't need to typedef, so you can implement your list just like this:

    struct list_el {
        int val;
        list_el *next;
    };
    
    bool delete_element(list_el *item)
    {
        list_el *cur = NULL;
        ...
    }
    

提交回复
热议问题