user1511417
user1511417

Reputation: 1940

How can I pass a "global" pointer to a SDL_Surface to a render-function of a class in C++?

My following problem is related to my previous question here.

I want to pass a "global" screen to a render-function of a class. screen has to be a pointer to a SDL_Surface, because the initial function SDL_SetVideoMode returns a pointer to a SDL_Surface.

Should I pass screen (set up in int main(){}) by reference to the render-function?

void renderClass::render (SDL_Surface &screen){...}

Edit: Or should I use a pointer?:

void renderClass::render (SDL_Surface *screen){...}

Or should I simply use

 extern SDL_Surface *screen;

in each header-file. (Since I'm using multiple source files)

Or is there any better way? I just want to get rid of pointers.

Upvotes: 0

Views: 353

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129314

I would pass it along. If you ever need to have two screens (or windows) rendered using the same function, you'd have to re-architect [aside from the horribleness of using global variables in general].

Edit: And I don't see any point in making it a pointer instead of a reference. Underneath things, it will be the same thing.

Upvotes: 1

Related Questions