C++ All-In-One Desk Reference for Dummies by John Paul Mueller & Jeff Cogswell
Author:John Paul Mueller & Jeff Cogswell [Mueller, John Paul & Cogswell, Jeff]
Language: eng
Format: epub
Tags: Reference:Computers
ISBN: 9780470317358
Publisher: For Dummies
Published: 2009-01-02T00:00:00+00:00
Figure 3-5: Use the Breakpoints window to access a number of breakpoints at once.
Watching, Inspecting, and Changing Variables
When you stop at a breakpoint in a program, you can do more than just look at the code. You can have fun with it! You can look at the current values of the variables, and you can change them.
Listing 3-2 is a sample program that you can use to try out these examples of inspecting, changing, and watching variables. Please note that this program is similar to Listing 3-1, earlier in this chapter, but you should see some differences. Specifically, we added a line to the SetNumberOfPieces member function
newamount = newamount * 20;
We added a new function called SpecialMath, and we added an i variable to main that is initialized to 10; then we doubled it, and we passed it into the SetNumberOfPieces function.
Listing 3-2: Using a Program for Breakpoints and Inspections
#include <iostream>
using namespace std;
class BrokenMirror
{
private:
int NumberOfPieces;
public:
int GetNumberOfPieces();
void SetNumberOfPieces(int newamount);
BrokenMirror() : NumberOfPieces(100) {}
};
int BrokenMirror::GetNumberOfPieces()
{
return NumberOfPieces;
}
void BrokenMirror::SetNumberOfPieces(int newamount)
{
newamount = newamount * 20;
NumberOfPieces = newamount;
}
int SpecialMath(int x)
{
return x * 10 - 5;
}
int main()
{
int i = 10;
BrokenMirror mirror;
i = i + SpecialMath(i);
mirror.SetNumberOfPieces(i);
cout << mirror.GetNumberOfPieces() << endl;
// Clear this comment if you want the application to stop to
// display the results.
// system(“PAUSE”);
return 0;
}
Watching the local variables
To watch the local variables in your program, follow these steps:
1. Compile this program with debug information on.
2. Set a breakpoint at the int i = 10; line in main.
3. Click Debug/Continue.
4. When the debugger stops at the breakpoint, click the Next Line button on the Debugger toolbar so that you are one line beyond the following line:
int i = 10;
5. Choose Debug⇒Debugging Windows⇒Watches.
You see the Watches window, as shown in Figure 3-6.
Figure 3-6: The Watches window shows the value of variables and objects.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9919)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9798)
The Mikado Method by Ola Ellnestam Daniel Brolund(9781)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8304)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7785)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7767)
Grails in Action by Glen Smith Peter Ledbrook(7699)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7561)
Windows APT Warfare by Sheng-Hao Ma(6883)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6611)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6481)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6420)
Kotlin in Action by Dmitry Jemerov(5068)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4320)
Functional Programming in JavaScript by Mantyla Dan(4040)
Solidity Programming Essentials by Ritesh Modi(4026)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3818)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3762)
The Ultimate iOS Interview Playbook by Avi Tsadok(3735)
