I'm not sure if this should go here or in the graphics forum, but it's mostly a C++ style question. In my main function, I create a pointer to one instance of a class I made (representing a window). Is it acceptable to have this pointer be global? Otherwise I have to pass it to all the functions in main.cpp. In addition, do I use const in this case? Here's the code, if it helps.
main.h:
Code:
#include <iostream>
#include <string>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "card.h"
#include "table.h"
using namespace std;
Window* gameWindow = NULL; //Here's the global I'm unsure about
int main(int argc, char** argv);
bool init();
int handleEvents();
int handleLogic();
int handleDisplay();
void cleanup();
main.cpp:
Code:
#include "main.h"
/** Main... duh */
int main(int argc, char* argv[]) {
if(!init()) return -1;
int runningCode = 0; //anything else signifies error
while(runningCode == 0) {
runningCode = handleEvents();
if(runningCode != 0) break;
runningCode = handleLogic();
if(runningCode != 0) break;
runningCode = handleDisplay();
}
cleanup();
return 0;
}
/** Initializes SDL and the Window object */
bool init() {
if(SDL_Init(SDL_INIT_EVERYTHING) == -1) return false;
gameWindow = new Window();
return true;
}
int handleEvents() {
SDL_Event event;
while(SDL_PollEvent(&event)) {
//TODO
}
}
int handleLogic() {
//TODO
}
int handleDisplay() {
//TODO
}
void cleanup() {
delete gameWindow;
}