I don't understand what I'm doing wrong. In my game.cpp, I have this:

void Game::input() {
    SDL_Event e;
    while(SDL_PollEvent(&e)) {
        if(e.type == SDL_QUIT) {running=false; cout << "Quitting" << endl;}
        if(e.type == SDL_KEYDOWN) {
            if(e.key.keysym.sym == SDLK_ESCAPE) {
        if(e.type == SDL_KEYUP) {
        SDL_GetMouseState(&mousex, &mousey);

In my player header file, I have:

class player {
    int getPlayerX();  //get player's x position
    int getPlayerY();  //get player's y position
    void moveSprite( SDL_Event& e );
    int xPos, yPos;

I'm getting the following error:

SDL_Event has not been declared"

on the line: void moveSprite( SDL_Event& e );

It seems like something simple but I've been staring at it for hours and I can't figure it out. Be gentle, I'm a third semester programming student.


1 Answer 1


If you aren't including "SDL.h", you need to forward-declare the union. Do note that forward declaring is only possible when you're using the type as a reference or a pointer.

So here's what you need to add to the player header file before the player class:

union SDL_Event;

You could also just #include "SDL.h" in the header file, but it's generally a good idea to reduce the amount of includes in headers.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .