Username
Username

Reputation: 3663

return type ‘SDL_Renderer {aka struct SDL_Renderer}’ is incomplete

I'm using SDL2. I want to be able to access private member _renderer with a member function.

Here's the relevant code:

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;
}

When I build, my compiler gives me this error:

../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

How can I fix this so getRenderer() returns the renderer?

Upvotes: 0

Views: 663

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103733

The SDL header file does not provide a definition of SDL_Renderer. It is an opaque type and should only be passed around by pointer or reference. Change your function's return type to SDL_Renderer*.

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

Upvotes: 3

Related Questions