Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: incomplete type is not allowed

in .h:

typedef struct token_t TOKEN;

in .c:

#include "token.h"

struct token_t
{
    char* start;
    int length;
    int type;
};

in main.c:

#include "token.h"

int main ()
{
    TOKEN* tokens; // here: ok
    TOKEN token;   // here: Error: incomplete type is not allowed
    // ...
}

The error I get in that last line:

Error: incomplete type is not allowed

What's wrong?

like image 385
Fabricio Avatar asked Oct 18 '14 11:10

Fabricio


People also ask

What is incomplete type not allowed in C++?

An incomplete class declaration is a class declaration that does not define any class members. You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete.

What does pointer to incomplete class type mean?

This error usually means that you are trying to follow a pointer to a class, but the compiler did not find the definition of that class (it found a declaration for the class, so it is not considered an unknown symbol, but it did not find a definition, so it is considered an incomplete class).


1 Answers

You need to move the definition of the struct into the header file:

/* token.h */

struct token_t
{
    char* start;
    int length;
    int type;
};
like image 120
NPE Avatar answered Sep 18 '22 00:09

NPE