Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c++
error
expected

Resolving the "expected specifier-qualifier-list before..." error

Educative Answers Team

The “expected specifier-qualifier-list before…” error occurs in C/C++ when the compiler cannot figure out a data structure​ or a variable’s type.

Consider the common error scenario shown in the code snippet below:

typedef struct
{
    char name[50];
    wheel wheels[4]; 
} car;

typedef struct
{
    int weight;
} wheel;

Note how the car struct uses the wheel struct in its definition. However, since the compiler parses the file from top to bottom, it does not know the existence of the wheel struct.

Solution

The solution is to always define a struct before using it in another struct:

typedef struct
{
    int weight;
} wheel;

typedef struct
{
    char name[50];
    wheel wheels[4]; // The wheel struct is already defined above so it can be used now.
} car;

Another common reason why this error occurs is the incorrect inclusion of header files. Make sure that you include header files correctly and that there is no circular inclusion.

RELATED TAGS

c++
error
expected
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring