Problem with enumeration "does not name type"

g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5

I have a problem and it seems to me that I am getting this error.

statemachine.h file

#ifndef STATEMACHINE_H_INCLUDED
#define STATEMACHINE_H_INCLUDED

#include "port.h"

enum state {
    ST_UNINITIALIZED = 0x01,
    ST_INITIALIZED   = 0x02,
    ST_OPENED        = 0x03,
    ST_UNBLOCKED     = 0x04,
    ST_DISPOSED      = 0x05
};

void state_machine(event evt, port_t *port);

#endif /* STATEMACHINE_H_INCLUDED */

file port.h

#ifndef PORT_H_INCLUDED
#define PORT_H_INCLUDED

#include <stdio.h>

#include "statemachine.h"

struct port_t {
    state current_state; /* Error 'state does not name a type */
    .
    .
};
#endif /* PORT_H_INCLUDED */

Thanks so much for any suggestions,

+5
source share
4 answers

Maybe you included "statemachine.h" in "port.h" and "port.h" in "statemachine.h"?

Try deleting the line:

#include "port.h"

From the file "statemachine.h"

Edit (according to Daniel's comment below):

Then you need to forward your type declaration port_tas follows:

...
    ST_DISPOSED       = 0x05
};

struct port_t;

void state_machine(event evt, port_t *port);
...
+7
source

, , states.h, . port.h statemachine.h .

.
states.h

#ifndef STATES_H_INCLUDED
#define STATES_H_INCLUDED

enum state {
    ST_UNINITIALIZED = 0x01,
    ST_INITIALIZED   = 0x02,
    ST_OPENED        = 0x03,
    ST_UNBLOCKED     = 0x04,
    ST_DISPOSED      = 0x05
};

#endif
+4

, :

  • port.h statemachine.h,
  • void state_machine(event evt, port_t *port); port.h

, .


, statemachine.h:

#ifndef STATEMACHINE_H_INCLUDED
#define STATEMACHINE_H_INCLUDED

struct port_t;

enum state {
    ST_UNINITIALIZED = 0x01,
    ST_INITIALIZED   = 0x02,
    ST_OPENED        = 0x03,
    ST_UNBLOCKED     = 0x04,
    ST_DISPOSED      = 0x05
};

void state_machine(event evt, port_t *port);

#endif /* STATEMACHINE_H_INCLUDED */

port.h statemachine.cpp

+1

gennrally ++. , , , , . , , ( ), .

. , state.h:

#ifndef STATE_H_INCLUDED
#define STATE_H_INCLUDED

enum state {
    ST_UNINITIALIZED = 0x01,
    ST_INITIALIZED   = 0x02,
    ST_OPENED        = 0x03,
    ST_UNBLOCKED     = 0x04,
    ST_DISPOSED      = 0x05
};

#endif /* STATE_H_INCLUDED*/

statemachine.h :

#ifndef STATEMACHINE_H_INCLUDED
#define STATEMACHINE_H_INCLUDED

#include "port.h"
#include "state.h"

void state_machine(event evt, port_t *port);

#endif /* STATEMACHINE_H_INCLUDED */

port.h:

#ifndef PORT_H_INCLUDED
#define PORT_H_INCLUDED

#include <stdio.h>
#include "state.h"

typedef struct port_tag port_t;

struct port_tag {
    state current_state; /* Error 'state does not name a type */
    .
    .
};
#endif /* PORT_H_INCLUDED */

, , .

+1

All Articles