Coding the main function

Let's rename the HelloSFML.cpp file as Main.cpp. Right-click on the HelloSFML file in the Solution Explorer and select Rename. Change the name to Main.cpp. This will be the file that contains our main function and the code that instantiates the Engine class.

Add the following code to Main.cpp:

#include "stdafx.h" 
#include "Engine.h" 
 
int main() 
{ 
   // Declare an instance of Engine 
   Engine engine; 
 
   // Start the engine VRRrrrrmmm 
   engine.run(); 
 
   // Quit in the usual way when the engine is stopped 
   return 0; 
} 

All we do is add an include directive for the Engine class, declare an instance of Engine, then call its run function. Everything will be handled by the Engine class until the player quits and the execution returns to main and ...

Get Beginning C++ Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.