forward declaration not working , does not have a type error

放肆的年华 提交于 2019-12-12 02:33:14

问题


I use forward declaration but still get ERROR: 'link' does not name a type. Why?

struct link;

struct node
{
    link *head_link;            <------- this is the error location
    node *next_node;
};

struct link
{
    link *next_link;
    node *connect_node;
};

回答1:


You declare a type called struct link, it's not just link, so write:

struct node
{
    struct link *head_link;
    struct node *next_node;
};

Alternatively, declare a type called link with a typedef.



来源:https://stackoverflow.com/questions/18009716/forward-declaration-not-working-does-not-have-a-type-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!