I am learning to create C++ applications using SDL2 library and I encountered a problem while trying to organise my code.
Here's a simple example ilustrating the situation:
void createWindow (SDL_Window *gameWindow)
{
gameWindow = SDL_CreateWindow(/* arguments here */);
}
int main (int argc, char* argv[])
{
SDL_Window* gameWindow = NULL;
createWindow(gameWindow);
// some code here...
}
Why doesn't it work? When I try to compile the code, SDL_GetError() screams: "Invalid Renderer".
When I make it that way
SDL_Window* createWindow (SDL_Window* gameWindow)
{
gameWindow = SDL_CreateWindow (/* arguments here*/);
return gameWindow;
}
it works. But I don't like it that way.
I may not understand something about pointers or the way SDL2 works on them, but I thought passing one to the function lets me operate directly on the variables intead of copies, so I don't have to return anything. For me it looks like I was operating on the copy of the variable adress, but not the variable itself.