Bocochoco Bocochoco - 7 months ago 68
C++ Question

error: using typedef-name after class

I can't figure out what the actual problem is with this.

typedef struct _actor
} _actor, Actor;

class Actor

I get this weird error message
actor.cpp:31: error: using typedef-name ‘Actor’ after ‘class’

Any idea what I did wrong here? Thank you :)


You are not allowed to define the symbol Actor more than once. The typedef statement already defines the symbol Actor as an alias for struct _actor before you attempt to declare a class with the same name.

I'm guessing you're using the gcc compiler. I get the following errors when I compile with gcc:

../src/main.cpp:113: error: using typedef-name ‘Actor’ after ‘class’
../src/main.cpp:111: error: ‘Actor’ has a previous declaration here

The first message (pointing the class Actor line in the program) states that you cannot declare a class with a typedef-name (Actor is already declared using typedef). The second message (pointing to the typedef struct _actor line in the program) is a little clearer and refers to the multiple declarations for Actor.

It is very common in C/C++ for a single class of error like this to result in multiple compiler errors and often the more helpful message is not the first reported.