gpt4 book ai didi

C++ 结构创建错误没有命名类型

转载 作者:行者123 更新时间:2023-11-27 23:44:14 30 4
gpt4 key购买 nike

当我运行我的程序时,每次使用 temp-> 时都会出现以下错误。

[错误] 请求 '* temp' 中的成员 'key',其指针类型为 'NodeType {aka Node*}'(也许您打算使用 '->'?)

代码有什么问题。

struct Node;
typedef Node *NodeType;

int NumNodes = 0;
const int SIZE = 100;
NodeType data[SIZE];


struct Node{
int key;
NodeType *left, *right;
};

NodeType *newNode(int value){
if(NumNodes == SIZE)
cout << "This Node Pool is full." << endl;
exit(1);

NodeType *temp = &data[NumNodes++];
temp->key = value;
temp->left = temp->right = NULL;
return temp;
}

最佳答案

struct Node
{
int key;
Node *left, *right;
};

int NumNodes = 0;
const int SIZE = 100;
Node data[SIZE];

Node* nNode(int value)
{

if(NumNodes == SIZE)
{
cout << "This is full" << endl;
exit(1);
}
else
{
Node* temp = &data[NumNodes++];
temp->key = value;
temp->left = temp->right = NULL;
return temp;
}
}

关于C++ 结构创建错误没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51926061/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com