Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Part 4: Advanced uses of C++

Part 4: Advanced uses of C++

The last part of the book discusses advanced uses of the C++ language: virtual functions, abstract classes, advanced overloaded operators, templates, exceptions, special casts, and run-time identification information.

Chapter 15, "Virtual Functions and Other Advanced Uses of Inheritance," describes the implementation of polymorphism with virtual functions—another jewel of object-oriented programming. First, it introduces the necessary (and often counterintuitive) background material on safe and unsafe type conversions between related and nonrelated classes. Then it applies this material to the task of processing heterogeneous lists of objects that belong to different (but related) classes and perform the same operation in a somewhat different manner. After that, it introduces the syntax of virtual functions and shows the dramatic simplification of the client code that these virtual functions allow.

In addition, Chapter 15 covers pure virtual functions and abstract classes and multiple inheritance. Although virtual functions are very useful for the processing of heterogeneous lists, the importance of this task is often exaggerated. This is even more true of multiple inheritance—its complexity far exceeds its utility from a software engineering point of view.

In Chapter 16, "Advanced Uses of Operator Overloading," I discuss advanced uses of operator overloading: unary operators, subscript and function call operators, and input/output operators. As with other uses of overloaded operators, these operators produce a nice syntax in the client code. Otherwise, the contribution of operator syntax to the quality of a C++ program is limited.

In Chapter 17, "Templates: Yet Another Design Tool," I introduce yet another C++ technique for design reuse: generic templates. The syntax of template definitions is quite complex. Their impact on the size of the object code and on the program execution time is often detrimental, and beginning C++ programmers should exercise restraint in building their own template classes.

However, the template classes that come with the C++ Standard Template Library (STL) are very well designed and should be used for complex data structures whenever possible. These template library classes give an excellent example of design and code reuse.

Chapter 18, "Programming with Exceptions," covers exception processing, yet another new C++ technique. This is a very interesting area of computer programming. You should probably try to use exceptions in a limited way to accumulate your own experience so that you can judge how useful this technique is for you. This chapter also discusses special casts and run-time object identification.

Chapter 19, "What We Have Learned," is a review chapter. In this chapter, I say everything that other authors say in their introductions. I postponed this until the end of the book to make sure that my words do not sound hollow. I hope that you will come to like this wonderful programming language and will be able to use it productively.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial