我刚刚开始编写代码,它做什么都没关系,因为它不编译,我也不知道为什么,它说:Error: argument of type "HNode *" is incompatible with parameter type "HNode *"上:getSL(root->left);。我真的不明白为什么会这样。我正在使用Visual Studio 2012进行编译。

我的代码(是的,还没有完成):

#include <stdio.h>
#include <stdlib.h>
typedef struct {
  char chr;
  struct HNode *left, *right;
} HNode;
typedef struct {
  char chr;
  int counter;
} Symbol;

int main()
{

}
Symbol * getSL(HNode * root)
{
    Symbol * s;
    if(!root) return NULL;
    if((!(root->left)) && (!(root->right)))
    {

    }
    else
    {
        getSL(root->left);
    }
}


您能向我解释我在做什么错以及如何解决吗?

最佳答案

使用这样的前向声明:

struct HNode;              //forward declaration
typedef struct HNode{      //note the struct tag here
  char chr;
  struct HNode *left, *right;
} HNode;

10-08 02:59