1

I'm trying to write a singleton class to hold the state of inputs from the user (mouse/keyboard data). The SDL API returns keyboard data as Uint8 pointer array, however, why I try to create the Uint8 pointer, I get these errors at the line w/ the uint8:

error C2143: syntax error : missing ';' before '*'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I've used Uint8 as a data type without defining it before, so I'm not sure what is causing the issue here. Here is my code:

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;
};
Donutfiend84
  • 125
  • 2
  • 5
  • 2
    Have you included _whatever SDL header_ that defines `Uint8`? And please please please don't call it a _keyword_... – K-ballo Jun 11 '12 at 05:07
  • Appologies, I've edited the question. I'm not sure where the definition comes from, SDL or otherwise. As a check though, I went back to an old file, that uses Uint8 w/o error, and included all the same header files, without any luck. – Donutfiend84 Jun 11 '12 at 05:17
  • Side note: with a singleton class, you should make its constructor private. Second [make sure you really want a singleton](http://en.wikipedia.org/wiki/Singleton_pattern#Drawbacks) – Shahbaz Jun 11 '12 at 09:33
  • Just so anybody doesn't get confused, it's `Uint8` not `Unit8`. – dud3 May 29 '17 at 19:58

1 Answers1

1

The type Uint8 is a typedef that is defined in one of the SDL header. If you want to use it, you need to include the SDL.h header in your file.

// You need this include if you want to use SDL typedefs
#include <SDL.h>

class InputState {
public:

    InputState()
    {};
    ~InputState()
    {};

    // ...

public:
    Uint8 *keys;

    // ...
};
Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85