gpt4 book ai didi

c - 为什么我收到 "redefinition of link as different kind of symbol"错误?

转载 作者:行者123 更新时间:2023-11-30 17:15:51 25 4
gpt4 key购买 nike

我将 link 定义为 struct STnode 指针,但出现错误。错误发生在这个头文件中,这是唯一定义 link 的地方。这是整个头文件

 // Top-down red-black tree header file
// These will have to change if data in node is more than just an int.
typedef int Key;
typedef Key Item;
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define eq(A, B) (key(A) == key(B))

typedef struct STnode* link;

struct STnode
{
Item item; // Data for this node
link l, r; // left & right links
char red; // RB color
int N; // subtree size
};

extern Item NULLitem;

void STinit(); // Initialize tree with just a sentinel

Item STsearch(Key v); // Find node for a key

Item STselect(int k); // Treat tree as flattened into an ordered array

int STinvSelect(Key v); // Inverse of STselect

void extendedTraceOn(); // Full tracing of intermediate trees

void basicTraceOn(); // Just trace down and up passes for insert

void traceOff(); // Run silent

void STinsert(Item item); // Insert an item. No uniqueness check

void verifyRBproperties(); // Ensure that tree isn't damaged

void STprintTree(); // Dumps out tree

void cleanUpUnbalanced(link h); // Includes subtree sizes and verifies a
tree
// built without balancing

每当我查找 link 最初定义的位置时,它都会将我定向到一个我什至在此代码中未使用的头文件。感谢您提前提供的所有帮助。

编辑:代码后将每个链接更改为STlink

 // Top-down red-black tree header file
// These will have to change if data in node is more than just an int.
typedef int Key;
typedef Key Item;
#define key(A) (A)
#define less(A, B) (key(A) < key(B))
#define eq(A, B) (key(A) == key(B))

typedef struct STnode* STlink; // Source

struct STnode // Error received - "redefinition of 'STnode' which directs me
to source above.
{
Item item; // Data for this node
STlink l, r; // left & right links
char red; // RB color
int N; // subtree size
};

extern Item NULLitem;

void STinit(); // Initialize tree with just a sentinel

Item STsearch(Key v); // Find node for a key

Item STselect(int k); // Treat tree as flattened into an ordered array

int STinvSelect(Key v); // Inverse of STselect

void extendedTraceOn(); // Full tracing of intermediate trees

void basicTraceOn(); // Just trace down and up passes for insert

void traceOff(); // Run silent

void STinsert(Item item); // Insert an item. No uniqueness check

void verifyRBproperties(); // Ensure that tree isn't damaged

void STprintTree(); // Dumps out tree

void cleanUpUnbalanced(STlink h); // Includes subtree sizes and verifies a
tree
// built without balancing

最佳答案

你说:

The error occurs in this header file, and this is the only place where link is defined.

不确定第一个 link 的定义位置,但您可以通过在代码部分使用 STlink 而不是 link 来解决此问题.

关于c - 为什么我收到 "redefinition of link as different kind of symbol"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29840098/

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