Sams Teach Yourself C++ in 21 Days
You create a reference by writing the type of the target object, followed by the reference operator (&), followed by the nam ...
Exploiting References 257 9 intOne: 5 rSomeRef: 5 intOne: 7 rSomeRef: 7 On line 8, a local integer variable,intOne, is declared. ...
intOne: 5 rSomeRef: 5 &intOne: 0x3500 &rSomeRef: 0x3500 OUTPUT 258 Day 9 Because the final two lines print memory addres ...
Exploiting References 259 9 Attempting to Reassign References (Not!) .................................................... Refere ...
Once again, on lines 8 and 9, an integer variable and a reference to an integer are declared. The integer is assigned the value ...
Exploiting References 261 9 LISTING9.4 References to Objects 1: // Listing 9.4 - References to class objects 2: 3: #include < ...
Null Pointers and Null References ...................................................................... When pointers are not i ...
Exploiting References 263 9 Passing an object by reference enables the function to change the object being referred to. On Day 5 ...
This program initializes two variables in main()and then passes them to the swap()function, which appears to swap them. When the ...
Exploiting References 265 9 23: 24: temp = *px; 25: *px = *py; 26: *py = temp; 27: 28: cout << “Swap. After swap, *px: “ & ...
function rather than where it belongs—on the function being called. Listing 9.7 rewrites the swap()function, using references. L ...
Exploiting References 267 9 Just as in the example with pointers, two variables are declared on line 10, and their values are pr ...
When Colonel John Roebling designed the Brooklyn Bridge, he worried in detail about how the concrete was poured and how the wire ...
Exploiting References 269 9 13: cout << “Enter a number (0 - 20): “; 14: cin >> number; 15: 16: error = Factor(numbe ...
The actual values needed, the square and cube of number, are not returned by using the return mechanism; rather, they are return ...
Exploiting References 271 9 18: cin >> number; 19: 20: result = Factor(number, squared, cubed); 21: 22: if (result == SUCC ...
On Day 5, you learned that these objects are copied onto the stack. Doing so takes time and memory. For small objects, such as t ...
Exploiting References 273 9 22: } 23: 24: SimpleCat::~SimpleCat() 25: { 26: cout << “Simple Cat Destructor...” << en ...
Listing 9.10 creates the SimpleCatobject and then calls two functions. The first function receives the Catby value and then retu ...
Exploiting References 275 9 yet it is given the address of the SimpleCat. This seriously exposes the original object to change a ...
«
10
11
12
13
14
15
16
17
18
19
»
Free download pdf