Shawn King
Shawn King

Reputation: 1

creating a class for graphics in C++ using SDL

I'm trying to create a game window for a cave story clone in C++, so first, I create the header file below, after that, I went to create the class file. When I finish the class I kept receiving the error that the argument type is incomplete with a parameter of type sdl_window and sdl_render. If anyone could help me figure out what I'm doing wrong.

Graphics.h

#ifndef GRAPHICS.h

#define GRAPHICS.h

struct SDL_window;
struct SDL_render;

class Graphics {
    public:
        Graphics();
        ~Graphics();
    private:
        SDL_window* window = NULL;
        SDL_render* render = NULL;
};

#endif

Graphics.cpp

#include <SDL.h>

#include "graphics.h"


/* Graphics class
* Holds all information dealing with graphics for the game
*/

Graphics::Graphics() {
    SDL_CreateWindowAndRenderer(640, 480, 0, &window, &render);
    SDL_SetWindowTitle(window, "Cavestory");
}

Graphics::~Graphics() {
    SDL_DestroyWindow(window);
}

Upvotes: -1

Views: 691

Answers (2)

Ave
Ave

Reputation: 33

I had similar problem despite having correct types, but in my case the problem was that I forgot to include SDL in .h file.

Upvotes: 0

user7860670
user7860670

Reputation: 37587

The problem is that you are declaring your own types unrelated to SDL types. Rewrite class to use appropriate types:

#include <SDL.h>

class Graphics {
  public:
    Graphics();
    ~Graphics();
  private:
    SDL_Window *   window = nullptr;
    SDL_Renderer * render = nullptr;
};

Upvotes: 5

Related Questions