< previous page page_149 next page >

Page 149
Hour 10
Advanced Pointers
One of the most powerful tools available to a C++ programmer is the capability to directly manipulate computer memory by using pointers. In this hour, you will learn
How to use pointers effectively
How to prevent memory problems when using pointers
How to create objects on the free store
Creating Objects on the Free Store.
Just as you can create a pointer to an integer, you can create a pointer to any object. If you have declared an object of type Cat, you can declare a pointer to that class and instantiate a Cat object on the free store, just as you can make one on the stack. The syntax is the same as for integers:
Cat *pCat = new Cat;
This calls the default constructorthe constructor that takes no parameters. The constructor is called whenever an object is createdon the stack or on the free store.

 
< previous page page_149 next page >

If you like this book, buy it!