04.01.2015 Views

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

Thinking in C++ 2nd ed Volume 1 Revision 6

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Chapter 10: Name Control. Creat<strong>in</strong>g names is a fundamental<br />

activity <strong>in</strong> programm<strong>in</strong>g, and when a project gets large, the number<br />

of names can be overwhelm<strong>in</strong>g. <strong>C++</strong> allows you a great deal of<br />

control over names: creation, visibility, placement of storage, and<br />

l<strong>in</strong>kage. This chapter shows how names are controll<strong>ed</strong> with two<br />

techniques. First, the static keyword is us<strong>ed</strong> to control visibility and<br />

l<strong>in</strong>kage, and its special mean<strong>in</strong>g with classes is explor<strong>ed</strong>. A far more<br />

useful technique for controll<strong>in</strong>g names at the global scope is <strong>C++</strong>’s<br />

namespace feature, which allows you to break up the global name<br />

space <strong>in</strong>to dist<strong>in</strong>ct regions.<br />

Chapter 11: References and the Copy-Constructor<br />

Constructor. <strong>C++</strong> po<strong>in</strong>ters<br />

work like C po<strong>in</strong>ters with the additional benefit of stronger <strong>C++</strong><br />

type check<strong>in</strong>g. <strong>C++</strong> also provides an additional way to handle<br />

addresses: from Algol and Pascal, <strong>C++</strong> lifts the reference, which lets<br />

the compiler handle the address manipulation while you use<br />

ord<strong>in</strong>ary notation. You’ll also meet the copy-constructor, which<br />

controls the way objects are pass<strong>ed</strong> <strong>in</strong>to and out of functions by<br />

value. F<strong>in</strong>ally, the <strong>C++</strong> po<strong>in</strong>ter-to-member is illum<strong>in</strong>at<strong>ed</strong>.<br />

Chapter 12: Operator Overload<strong>in</strong>g. This feature is sometimes call<strong>ed</strong><br />

“syntactic sugar;” it lets you sweeten the syntax for us<strong>in</strong>g your type<br />

by allow<strong>in</strong>g operators as well as function calls. In this chapter you’ll<br />

learn that operator overload<strong>in</strong>g is just a different type of function<br />

call and you’ll learn how to write your own, especially the<br />

sometimes-confus<strong>in</strong>g uses of arguments, return types, and the<br />

decision of whether to make an operator a member or friend.<br />

Chapter 13: Dynamic Object Creation. How many planes will an airtraffic<br />

system have to handle How many shapes will a CAD system<br />

ne<strong>ed</strong> In the general programm<strong>in</strong>g problem, you can’t know the<br />

quantity, lifetime, or type of objects ne<strong>ed</strong><strong>ed</strong> by your runn<strong>in</strong>g<br />

program. In this chapter, you’ll learn how <strong>C++</strong>’s new and delete<br />

elegantly solve this problem by safely creat<strong>in</strong>g objects on the heap.<br />

Chapter 14: Inheritance and Composition. Data abstraction allows<br />

you to create new types from scratch, but with composition and<br />

<strong>in</strong>heritance, you can create new types from exist<strong>in</strong>g types. With<br />

composition, you assemble a new type us<strong>in</strong>g other types as pieces,<br />

and with <strong>in</strong>heritance, you create a more specific version of an<br />

30 <strong>Th<strong>in</strong>k<strong>in</strong>g</strong> <strong>in</strong> <strong>C++</strong> www.BruceEckel.com

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

Saved successfully!

Ooh no, something went wrong!