Search code examples
c++cdata-structuresternary-tree

error: pointer to incomplete class type is not allowed


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.


Solution

  • 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.