Sams Teach Yourself C++ in 21 Days
33: cout << “Simple Cat Destructor...” << endl; 34: } 35: 36: const SimpleCat * const FunctionTwo 37: (const SimpleC ...
Exploiting References 277 9 SimpleCathas added two accessor functions,GetAge()on line 13, which is a constfunction, and SetAge() ...
11: ~SimpleCat(); 12: 13: int GetAge() const { return itsAge; } 14: void SetAge(int age) { itsAge = age; } 15: 16: private: 17: ...
Exploiting References 279 9 Making a cat... Simple Cat constructor... Frisky is 1 years old Frisky is 5 years old Calling Functi ...
In this example, a pointer to int,pInt, is declared and initialized with the memory returned by the operator new. The address in ...
Exploiting References 281 9 The counterargument is that the type is Cat. The &is part of the “declarator,” which includes th ...
LISTING9.13 Returning a Reference to a Nonexistent Object 1: // Listing 9.13 2: // Returning a reference to an object 3: // whic ...
Exploiting References 283 9 On lines 7–17,SimpleCatis declared. On line 29, a reference to a SimpleCatis initialized with the re ...
24: SimpleCat & TheFunction(); 25: 26: int main() 27: { 28: SimpleCat & rCat = TheFunction(); 29: int age = rCat.GetAge( ...
Exploiting References 285 9 So far, so good. But how will that memory be freed? You can’t call delete on the refer- ence. One cl ...
Summary .............................................................................................................. Today, yo ...
Exploiting References 287 9 Workshop ........................................................................................... ...
6: CAT(int age) { itsAge = age; } 7: ~CAT(){} 8: int GetAge() const { return itsAge;} 9: private: 10: int itsAge; 11: }; 12: 13: ...
DAY 10 WEEK 2 Working with Advanced Functions On Day 5, “Organizing into Functions,” you learned the fundamentals of work- ing w ...
The Rectangleclass, demonstrated in Listing 10.1, has two DrawShape()functions. One, which takes no parameters, draws the rectan ...
Working with Advanced Functions 291 10 43: for (int j = 0; j< width; j++) 44: { 45: std::cout << “*”; 46: } 47: std::co ...
The compiler decides which method to call based on the number and type of parameters entered. You can imagine a third overloaded ...
Working with Advanced Functions 293 10 35: int printWidth; 36: int printHeight; 37: 38: if (UseCurrentValue == true) 39: { 40: p ...
Listing 10.2 replaces the overloaded DrawShape()function with a single function with default parameters. The function is declare ...
Working with Advanced Functions 295 10 programming—the calling program does not have to do anything to ensure that the object st ...
«
11
12
13
14
15
16
17
18
19
20
»
Free download pdf