Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with enum "does not name a type'

Tags:

c++

enums

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

I am having a problem and I seem to find out way I am getting this error.

file statemachine.h

#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 */

Many thanks for any suggestions,

like image 614
ant2009 Avatar asked Apr 18 '11 09:04

ant2009


1 Answers

Could it be that you're including "statemachine.h" in "port.h" and "port.h" in "statemachine.h"?

Try removing the line:

#include "port.h"

From the file "statemachine.h"

Edit (as per Daniel's comment below):

Then you need to forward declare your port_t type as follows:

...
    ST_DISPOSED       = 0x05
};

struct port_t;

void state_machine(event evt, port_t *port);
...
like image 185
Nick Avatar answered Sep 28 '22 14:09

Nick