11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

150Part II: Becoming a Functional C++ ProgrammerA Segmentation Fault usually indicates an errant pointer of some type.You’ll have to reset the program back to the beginning before trying again.Click OK to acknowledge the error and then the Program Reset from theDebug menu or the Stop Execution command from the Debug toolbar to makesure that everything within the debugger is reset back to the beginning. It’salways a good idea to reset the debugger before starting again — doing so isnecessary if the program is not at the starting point, and resetting the debuggerwon’t hurt anything if the program is already at the beginning.To see exactly where the problem occurs, execute just a part of the program.The debugger lets you do this through what is known as a breakpoint. Thedebugger stops the program if execution ever passes through a breakpoint.The debugger then gives control back to the programmer.Now set a breakpoint at the first executable statement by clicking in thetrough just to the left of the reference to cout immediately after main() orpressing F5 as shown in Table 10-1. A small red circle with a check appears.The display now appears like the one shown in Figure 10-2.Now execute the program under the debugger again, either by selecting theDebug item under the Debug menu, by clicking the blue check mark on thedebug toolbar, or by pressing F8. Program execution starts like normal butimmediately stops on the first line. The line containing the breakpoint turnsfrom red to blue, indicating that execution has halted at that point.Figure 10-2:Abreakpointshows up asa small redcircle with acheck.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!