我有一个文件input_service.h
和一个文件instances.h
,在instances.h
中我有一个宏Extends_Instance
,当我在instances.h
中使用该宏时,它工作正常,但当我在input_service.h
中使用它时,它导致<error-type>
。input_service.h
:
#pragma once
#include <placeholder/instances/instances.h>
#include <placeholder/ff.h>
typedef enum e_keyState {
KS_NOT_PRESSED = 0b00000000,
KS_JUST_PRESSED = 0b00000010,
KS_JUST_RELEASED = 0b00000100,
KS_HELD = 0b00000010
} e_keyState;
// % (KeyDown, KeyPressed, KeyReleased, KeyUp) -> `@property InputService->m_getKeyState`
typedef struct InputService {
Extends_Instance; // !!!!!! ERROR HERE !!!!!!
// Extends_Instance -> <error-type>
//
// & `(e_keyState & KS_DOWN) == 0` -> Key is being held
// => `(e_keyState & KS_RELEASED) == 0` -> Key was just released
// => ... see `@enum e_keyState`
public method(m_getKeyState, e_keyState)(struct InputService *self, char key_code);
internal method(m_frameBegun, void)(struct InputService *self);
internal readOnly ALLEGRO_KEYBOARD_STATE last_state;
internal readOnly ALLEGRO_KEYBOARD_STATE now_state;
} InputService;
constructor function InputService* service_create_input_service(void);
instances.h
的片段
#define Extends_Instance char *name; \
char *class_name; \
size_t id; \
struct Instance *parent; \
struct Instance *children[MAX_CHILDREN]; \
uint32_t children_count; \
method (m_draw, void)(struct Instance *self); \
method (m_debugDraw, void)(struct Instance *self); \
hashtable_t children_fi; \
bool enable_debugging
// & (? `@class Instance`) !
typedef struct Instance { Extends_Instance; } Instance; !!!!!! NO ERROR HERE?? !!!!!!
编译器错误:
../placeholder/instances/services/input_service.h:16:9: error: expected specifier-qualifier-list before ‘Extends_Instance’
16 | Extends_Instance;
| ^~~~~~~~~~~~~~~~
1条答案
按热度按时间but5z9lq1#
"我也许是个白痴"
在定义宏之前,不要包含使用宏的头文件,抱歉浪费了大家的时间。愚蠢的错误。