关注我之前的question:
现在我有了这个:
xml_list *text1(xml_list *);
xml_list *text(xml_list *);
//operation: text1(elem)
xml_list *text1(xml_list *elem){
if(isText(elem)){
return Cons(elem,Nil());
}
else{
return text(childeren(elem));
}
}
//operation: text(elem)
xml_list *text(xml_list *elem){
if(isEmpty(elem)){
return Nil();
}
return append(text1(head(elem)),text(tail(elem)));
}
当我运行此操作时,我收到xml_list * text1:
的警告incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
if(isText(elem)){
也是下一行的警告:
warning: incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
return Cons(elem,Nil());
再次发出警告:
warning: incompatible pointer types passing 'xml_list *' (aka 'struct xml_list_struct *') to parameter of type 'xml *' (aka 'struct xml_struct *') [-Wincompatible-pointer-types]
return text(children(elem));
如何让这些警告消失?
答案 0 :(得分:1)
错误不言自明:
您的isText
,Cons
和children
方法需要xml*
(指向xml_struct
的指针)。您正在传递xml_list*
(指向xml_list_struct
的指针)。
通过传递正确的指针(xml*
)或修改方法以接受您拥有的指针(xml_list*
)来使警告消失