返回类型'SDL_Renderer {aka struct SDL_Renderer}'不完整

时间:2016-02-07 07:16:14

标签: c++ sdl sdl-2

我正在使用SDL2。我希望能够使用成员函数访问私有成员_renderer

以下是相关代码:

Graphics.h

#ifndef GRAPHICS_H
#define GRAPHICS_H

class Graphics {
public:
    Graphics();
    ~Graphics();
    SDL_Renderer    getRenderer();
private:
    SDL_Renderer    *_renderer;


#endif

Graphics.cpp

#include <SDL2/SDL.h>
#include "Graphics.h"

SDL_Renderer Graphics::getRenderer(){
    return _renderer;
}

当我构建时,我的编译器给了我这个错误:

../source/src/Graphics.cpp: In member function ‘SDL_Renderer Graphics::getRenderer()’:
../source/src/Graphics.cpp:49:36: error: return type ‘SDL_Renderer {aka struct SDL_Renderer}’ is incomplete
 SDL_Renderer Graphics::getRenderer(){
                                    ^
make: *** [source/src/Graphics.o] Error 1
source/src/subdir.mk:27: recipe for target 'source/src/Graphics.o' failed

如何解决此问题,以便getRenderer()返回渲染器?

1 个答案:

答案 0 :(得分:2)

SDL头文件未提供SDL_Renderer的定义。它是一个opaque类型,只能通过指针或引用传递。将函数的返回类型更改为SDL_Renderer*

SDL_Renderer* Graphics::getRenderer(){
    return _renderer;
}