简体   繁体   中英

Pointer to Incomplete Class type not allowed

I am implementing a bubble sort function, where it sorts words. the swap function words perfectly fine but i am unable to get the error. Tried searching online but could not get somthing useful. I have marked where i get the error.

Thank you for the help.

void sortWord (struct node** head) {
    struct node* temp  = (*head);
    struct node* temp2 = (*head);

    int i;
    int j;
    int counter = 0;
    while(temp != NULL)
    {
        temp = temp->next; //<-- this is where i get the error.
        counter++;
    }
    for( i = 1; i<counter; i++)
    {
        temp2=(*head);
        for(j = 1; j<counter-1;j++)
        {
            if(wordCompare(temp2,nodeGetNextNode(temp2))>0)
            {
                swap(head,temp2,nodeGetNextNode(temp2));
                continue;
            }
        }
        temp2 = nodeGetNextNode(temp2);
    }
}

This error is given when you are trying to use a struct that has been forward-declared, but not defined . While it is absolutely OK to declare and manipulate pointers to such structs, trying to dereference them is not OK, because the compiler needs to know their size and layout in order to perform the access.

Specifically, in your case the compiler does not know that struct node has next , so

temp->next

does not compile.

You need to include a definition of the struct node in the compilation unit where you define your sortWord function to fix this problem.

You should replace this line:

temp = temp->next;

with that line:

temp = nodeGetNextNode(temp);

The reason is that in this code you know nothing about the structure of node . I guess that's why you used nodeGetNextNode function for temp2. you just need to used it for temp as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM