Best way to pass SDL objects in c++
I started a small game in C++ using SDL. I have been looking into pointers
and references and I understand the differences. This question is similar
to others asked before but I had no luck finding exactly what I need.
int main(int argc, char* argv[])
{
SDL_Renderer* renderer = NULL;
TTF_Font* font = NULL;
renderer = SDL_CreateRenderer(window, -1, 0);
if(renderer == NULL)
{
return 1;
}
font = TTF_OpenFont("OpenSans.ttf", 12);
if(font == NULL)
{
return 1;
}
texture = renderText(...)
return 0;
}
SDL_Texture* renderText(...)
{
}
This is part of my program, now I need to pass the renderer and font
objects to the renderText() function. My question is, should I pass them
as pointers (which they already are), or as reference?
This is how I think it would look:
SDL_Texture* renderText(SDL_Renderer* renderer,...)
{
}
renderText(renderer,...)
or
SDL_Texture* renderText(SDL_Renderer &renderer,...)
{
}
renderText(*renderer,...)
Also later in renderText() func I have to pass pointer of the SDL_Renderer
into other SDL functions so I would have to use & again in the second
case. Thanks for help.
No comments:
Post a Comment