C struct creation错误未命名类型

Jus*_*ney 4 c struct

我只是想设置一个简单的递归结构而不需要太多的C知识(必须以某种方式学习)

这是我的make编译行

g++ -o cs533_hw3 main.c
Run Code Online (Sandbox Code Playgroud)

这是我的代码

typedef struct Node Node;

struct Node
{
    int texture;
    float rotation;
    Node *children[2];
};

Node rootNode;
rootNode.rotation
Run Code Online (Sandbox Code Playgroud)

这是我在最后一行的错误

error: 'rootNode' does not name a type
Run Code Online (Sandbox Code Playgroud)

Car*_*rum 19

代码必须在C中的函数中.您可以在全局范围内声明变量,但不能在其中放置语句.

更正示例:

typedef struct Node Node;

struct Node
{
    int texture;
    float rotation;
    Node *children[2];
};

Node rootNode;

int main(void)
{
    rootNode.rotation = 12.0f;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)