Sams Teach Yourself C++ in 21 Days
236 Day 8 Animal *pDog = new Animal; // allocate memory delete pDog; //frees the memory pDog = 0; //sets pointer to null //... d ...
Understanding Pointers 237 8 On line 14, the memory allocated on line 9 is returned to the free store by a call to delete. This ...
Creating Objects on the Free Store...................................................................... Just as you can create ...
Understanding Pointers 239 25: cout << “Destructor called. “ << endl;^8 26: } 27: 28: int main() 29: { 30: cout < ...
Accessing the members of an object when using a pointer is a little more complex. To access the Catobject on the free store, you ...
Understanding Pointers 241 19: using namespace std;^8 20: SimpleCat * Frisky = new SimpleCat; 21: cout << “Frisky is “ < ...
14: int GetWeight() const { return *itsWeight; } 15: void setWeight (int weight) { *itsWeight = weight; } 16: 17: private: 18: i ...
Understanding Pointers 243 8 The destructor (lines 28–32) cleans up the allocated memory. Because this is the destruc- tor, ther ...
LISTING8.8 Using the thisPointer 1: // Listing 8.8 2: // Using the this pointer 3: 4: #include <iostream> 5: 6: class Rect ...
Understanding Pointers 245 8 theRect is 10 feet long. theRect is 5 feet wide. theRect is 20 feet long. theRect is 10 feet wide. ...
LISTING8.9 Creating a Stray Pointer 1: // Listing 8.9 - Demonstrates a stray pointer 2: 3: typedef unsigned short int USHORT; 4: ...
Understanding Pointers 247 8 This is a listing you should avoid running because it could lock up your machine. On line 8,pIntis ...
248 Day 8 pIntwas assigned the value 20 —or 00 14in hexadecimal notation. Because pIntstill pointed to the same address, the fi ...
Understanding Pointers 249 8 The trick to keeping this straight is to look to the right of the keyword constto find out what is ...
30: int main() 31: { 32: Rectangle* pRect = new Rectangle; 33: const Rectangle * pConstRect = new Rectangle; 34: Rectangle * con ...
Understanding Pointers 251 8 but the rectangle is not constant, so methods such as GetWidth()and SetWidth()can be used. Using a ...
Q&A .................................................................................................................... Q W ...
Understanding Pointers 253 8 What is the difference between the indirection operator and the address-of operator? What is the d ...
...
DAY 9 WEEK 2 9 Exploiting References Yesterday, you learned how to use pointers to manipulate objects on the free store and how ...
«
9
10
11
12
13
14
15
16
17
18
»
Free download pdf