我只是想在没有太多 C 知识的情况下建立一个简单的递归结构(必须以某种方式学习)
这是我的编译行
g++ -o cs533_hw3 main.c
这是我的代码
typedef struct Node Node;
struct Node
{
int texture;
float rotation;
Node *children[2];
};
Node rootNode;
rootNode.rotation
这是我在最后一行的错误
error: 'rootNode' does not name a type
最佳答案
代码必须在 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;
}
关于C 结构创建错误未命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392059/