简体   繁体   English

使用SDL在C ++中为图形创建类

[英]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. 我正在尝试为C ++中的洞穴故事克隆创建游戏窗口,因此,首先,我在下面创建了头文件,然后,我创建了类文件。 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. 当我完成课程时,我不断收到错误消息,指出参数类型为sdl_window和sdl_render的参数类型不完整。 If anyone could help me figure out what I'm doing wrong. 如果有人可以帮助我弄清楚我在做什么错。

Graphics.h 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 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);
}

The problem is that you are declaring your own types unrelated to SDL types. 问题是您要声明自己的类型与SDL类型无关。 Rewrite class to use appropriate types: 重写类以使用适当的类型:

#include <SDL.h>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM