Reading the tape ---------------- When your debugger fails you, like for example you can only see a problem when compiling without debug information enabled (and yes, it does happen), you will have to resort to the ancient art of "reading the tape". The idea is to print meaningful output messages at strategic locations to work out exactly where the program's execution deviates from your idea of what it should be doing. The following example demonstrates that reading the tape is required, and although the method is inflexible and not very efficient - it does get results.
class LightSwitch
{
public:
bool isOn() { return IsOn; }
void toggle() { IsOn = !IsOn; }
private:
bool IsOn;
};
int main(void)
{
// we make a new light switch
LightSwitch *l = new LightSwitch();
// Turn it on
if (l->isOn() != true)
l->toggle();
// It's still not on?!
if (l->isOn() != true)
printf("The light will not turn on\n");
else
printf("The light is on\n");
}