11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table of ContentsixChapter 13: Making Classes Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167Activating Our Objects ................................................................................168Simulating real-world objects ...........................................................168Why bother with member functions? ..............................................169Adding a Member Function.........................................................................169Creating a member function .............................................................170Naming class members......................................................................171Calling a Member Function .........................................................................171Accessing a member function...........................................................172Accessing other members from a member function .....................174Scope Resolution (And I Don’t Mean How Well Your Microscope Works) .........................................................................175Defining a Member Function in the Class .................................................177Keeping a Member Function After Class ...................................................179Overloading Member Functions.................................................................181Chapter 14: Point and Stare at Objects . . . . . . . . . . . . . . . . . . . . . . . . .183Defining Arrays of and Pointers to Simple Things ...................................183Declaring Arrays of Objects........................................................................184Declaring Pointers to Objects.....................................................................185Dereferencing an object pointer.......................................................186Pointing toward arrow pointers .......................................................187Passing Objects to Functions .....................................................................187Calling a function with an object value ...........................................188Calling a function with an object pointer ........................................189Calling a function by using the reference operator .......................191Why Bother with Either Pointers or References? ....................................192Returning to the Heap .................................................................................192Comparing Pointers to References ............................................................193Why Not Use References Rather Than Pointers?.....................................193Linking Up with Linked Lists ......................................................................195Performing other operations on a linked list..................................196Hooking up with a LinkedListData program ...................................197A Ray of Hope: A List of Containers Linked to the C++ Library .............200Chapter 15: Protecting Members: Do Not Disturb . . . . . . . . . . . . . . . .201Protecting Members ....................................................................................201Why you need protected members..................................................201Discovering how protected members work....................................202Making an Argument for Using Protected Members................................204Protecting the internal state of the class ........................................204Using a class with a limited interface ..............................................205Giving Non-Member Functions Access to Protected Members..............205

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!