Uint8 - 缺少类型说明符

Uint8 - Missing Type specifier

本文关键字:类型 说明符 Uint8      更新时间:2023-10-16

我正在尝试编写一个单例类来保存来自用户的输入状态(鼠标/键盘数据)。SDL API 将键盘数据作为 Uint8 指针数组返回,但是,为什么我尝试创建 Uint8 指针,我在带有 uint8 的行中收到以下错误:

error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

我以前没有定义过 Uint8 作为数据类型,所以我不确定是什么导致了这里的问题。这是我的代码:

class InputState {
public:
    InputState()
    {};
    ~InputState()
    {};

    static InputState *getInputState(void)
    {
        static InputState *state = new InputState();
        return state;
    };
public:
    Uint8 *keys;
    struct MouseState
    {
        int LeftButtonDown;
        int RightButtonDown;
        int MiddleButtonDown;
        int x;
        int y;
        MouseState ()
        {
            LeftButtonDown = 0;
            RightButtonDown = 0;
            MiddleButtonDown = 0;
            x = 0;
            y = 0;
        }
    };
    MouseState *mouseState;
};

类型 Uint8 是在其中一个 SDL 标头中定义的 typedef。如果要使用它,则需要在文件中包含SDL.h标头。

// You need this include if you want to use SDL typedefs
#include <SDL.h>
class InputState {
public:
    InputState()
    {};
    ~InputState()
    {};
    // ...
public:
    Uint8 *keys;
    // ...
};