質問

I am stumped at this step while implementing a ternary tree:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct tnode *Tptr;
    typedef struct node
{
    char splitchar;
    Tptr lokid,eqkid,hikid;

}Tnode;

int research(Tptr p,char *s)
{
    if (!p) return 0;
    if (*s<p->
}

int main(){
    return 0;
}

When I move the mouse icon near the p, it shows me a red color and error:

pointer to incomplete class type is not allowed

My question is exactly what is an incomplete class? Please help me, thanks.

役に立ちましたか?

解決

You've typedef'd Tptr as a struct tnode *, but tnode is not defined or even declared. Perhaps you meant to name your node struct tnode instead?

BTW, there's an easy way to keep that from happening in the future...

typedef struct tnode {
    ...
} Tnode, *Tptr;

At that point, Tptr is always an alias to the correct type, even if you change tnode's name to something else.

他のヒント

incomplete class (or type) is the type that is forward declared, but is not defined. Just like your tnode. Probably you should replace node by tnode as the tag of structure in your example to get what you need.

"incomplete class type" suggests that your compiler believes this is C++ code rather than C code, since C does not have classes.

Note that line 5 makes Tptr a name for struct tnode *—pointer to a struct named "tnode", not "node" but "tnode", lowercase t, node. Line 6 starts a typedef, then starts defining a struct named "node", no "t", just "node". Line 11 finishes off the definition of "struct node", and then supplies a name for the earlier typedef: "Tnode", uppercase T, node.

You have four different names here now: Tptr, Tnode, tnode, and node. The one with a lowercase "t" has never been "completed", so it's an "incomplete type" (but not class, because C does not have classes).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top