I am new to c++, and i have difficulties understannding some of it's parts, especially in memory management. This is one of my first projects, an SFML lib game. So i get an access violation error, in this code:
include "Game.h"
void Game::Start()
{
if (_gameState == Uninitialized)
return;
_mainWindow.create(sf::VideoMode(1024, 768, 32), "Hi!");
_gameState = Game::Playing;
while (!IsExiting()){
GameLoop();
}
_mainWindow.close();
}
bool Game::IsExiting(){
if (_gameState == Game::Exiting)
{
return true;
}
else
{
return false;
}
}
void Game::GameLoop(){
sf::Event currentEvent;
while (_mainWindow.pollEvent(currentEvent))
{
switch (_gameState)
{
case Game::Playing:
{
_mainWindow.clear(sf::Color(255, 255, 255));
_mainWindow.display();
if (currentEvent.type == sf::Event::Closed)
{
_gameState = Game::Exiting;
}
break;
}
}
}
}
Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;
The error happens, when code gets to the very last line of code, the _mainWIndow declaration. I understand, that problem most probably happened because i do not completely understand the quirks of static. But i still dont yet understand what causes the problem, and how to solve it.
The Game class:
class Game
{
public:
static void Start();
private:
static bool IsExiting();
static void GameLoop();
enum GameState {Uninitialized, ShowingSplash, Paused, ShowingMenu, Playing, Exiting};
static GameState _gameState;
static sf::RenderWindow _mainWindow;
};