错误:不允许指向不完整类类型的指针。 SDL / C ++

时间:2015-01-02 14:57:32

标签: c++ class pointers sdl

所以我是SDL的新手,在我的代码中我收到了这个错误:

  

不允许指向不完整类类型的指针。

以下是代码:

的main.cpp

#include <SDL.h>
#include "events.h"

int main(int argc, char ** argv)
{
SDL_Renderer* ro;
SDL_Texture* to;
SDL_Surface* so;
SDL_Window* wo;


SDL_FreeSurface(so->getImage());

SDL_SetRenderDrawColor(ro->getRenderer(), 255, 255, 255, 255); // error here

// handle events

events mo;
mo.handleEvents();

// cleanup SDL

SDL_DestroyTexture(to->getTexture()); // error here
SDL_DestroyRenderer(ro->getRenderer()); // error here
SDL_DestroyWindow(wo->getWindow()); // error here
SDL_Quit();

return 0;
}

events.h

#pragma once
class events
{
public:
events();
void handleEvents();
SDL_Renderer* getRenderer();
SDL_Texture* getTexture();
SDL_Surface* getImage();
SDL_Window* getWindow();
~events();
private:
SDL_Event event;
int x;
int y;
bool quit;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Surface *image;
SDL_Window *window;
};

events.cpp

#include "events.h"
#include <SDL.h>


events::events()
{
SDL_Event event;
int x = 288;
int y = 208;
bool quit = false;
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, image);
SDL_Surface *image = SDL_LoadBMP("face.bmp");
SDL_Window *window = SDL_CreateWindow("SDL2 Keyboard/Mouse events", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
}


events::~events()
{
}

void events::handleEvents(){

SDL_Init(SDL_INIT_VIDEO);

while (!quit)
{
    SDL_Delay(10);
    SDL_PollEvent(&event);

    switch (event.type)
    {
    case SDL_QUIT:
        quit = true;
        break;

    case SDL_KEYDOWN:
        switch (event.key.keysym.sym)
        {
        case SDLK_LEFT:
            x -= 5;
            break;
        case SDLK_RIGHT:
            x += 5;
            break;
        case SDLK_UP:
            y -= 5;
            break;
        case SDLK_DOWN:
            y += 5;
            break;
        }
        break;
    }

    SDL_Rect dstrect = { x, y, 64, 64 };

    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, texture, NULL, &dstrect);
    SDL_RenderPresent(renderer);
  }
}

SDL_Renderer* events::getRenderer(){
return renderer;
}

SDL_Texture* events::getTexture(){
return texture;
}

SDL_Surface* events::getImage(){
return image;
}

SDL_Window* events::getWindow(){
return window;
}

1 个答案:

答案 0 :(得分:0)

编译events.cpp时出现错误,因为events.h在使用SDL数据类型之前不包含SDL.h。然后在events.cpp中,SDL.h之后包含events.h,因此错误。