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

我遇到了问题,我似乎发现了遇到此错误的方法。

文件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 */

文件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 */

非常感谢您的任何建议,

最佳答案

难道您要在“port.h”中包含“statemachine.h”,而在“statemachine.h”中包含“port.h”吗?

尝试删除该行:

#include "port.h"

从文件“statemachine.h”

编辑(根据下面Daniel的评论):

然后,您需要转发声明port_t类型,如下所示:
...
    ST_DISPOSED       = 0x05
};

struct port_t;

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

07-28 06:32