C++ assertions
In this project, we will be using C++ assertions. As usual, there is more to this topic than we will discuss here, but we can still do some useful things with just an introduction.
We can use the #define
preprocessor statement in a class to define a value for the entire project. We do so with the following code:
#define debuggingOnConsole
This code would be written at the top of a header file. Now, throughout the project, we can write code like the following:
#ifdef debuggingOnConsole     // C++ code goes here #endif
The #ifdef debuggingOnConsole
statement checks whether the #define
debuggingOnConsole
statement is present. If it is, then any C++ code up to the #endif
statement will be included in the game. We can then choose to comment out the #define
statement to switch our debugging code on or off.
Typically, we will include code such as the following in the #ifdef
blocks:
#ifdef debuggingOnConsole     ...