-1

在我之前的问题之后:

现在我有这个:

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));

我怎样才能让这些警告消失?

4

1 回答 1

1

该错误是不言自明的:

您的isText,Conschildren方法期望xml*(指向 an 的指针xml_struct)。您正在传递一个xml_list*(指向一个的指针xml_list_struct)。

您可以通过传递正确的指针 ( xml*) 或修复方法以接受您拥有的指针 ( xml_list*)来消除警告

于 2013-04-04T13:08:58.963 回答