gpt4 book ai didi

c - 错误 : conflicting types

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:02 25 4
gpt4 key购买 nike

我正在为一项作业编写 C 代码。

这是相关代码:

 //operation: text(elem)
xml_list *text(xml_list *elem){
if(isEmpty(elem)){
return Nil();
}
return append(text1(head(elem)),text(tail(elem)));
}

//operation: text1(elem)
xml_list *text1(xml_list *elem){
if(isText(elem)){
return Cons(elem,Nil());
}
else{
return text(childeren(elem));
}
}

这给了我错误:error: conflicting types for 'text1'
xml_list *text1(xml_list *elem){

我无法找出问题的根源。我现在已经为此连续工作了 8 个小时,对此我有点失去理智。请有人帮助我

最佳答案

你使用text1

xml_list *text(xml_list *elem){
if(isEmpty(elem)){
return Nil();
}
return append(text1(head(elem)),text(tail(elem)));
}

在它被声明之前,所以编译器使用(不幸的是)旧的“隐式 int”规则,并假设 text1 返回一个 int.

当遇到声明它返回 xml_list* 的定义时,这与从隐式 int 声明中获得的类型冲突。

在 header 中声明您的函数,并将其包含在源代码中,以便在使用函数时知道所有原型(prototype)。

关于c - 错误 : conflicting types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15796223/

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