{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter06 -...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Viewing Hints  ] [  Exercise Solutions  ] [  Volume 2  ] [  Free Newsletter  ]  Seminars  ] [  Seminars on CD ROM  ] [  Consulting  ]  Thinking in C++, 2nd ed. Volume 1 © 2000 by Bruce Eckel Previous Chapter  ] [  Table of Contents  ] [  Index  ] [  Next Chapter  ]  6: Initialization & Cleanup Chapter 4 made a significant improvement in library  use by taking all the scattered components of a typical  C library and encapsulating them into a structure (an abstract data type, called a  class  from now on).  This not only provides a single unified point of entry into a library component, but it also hides the  names of the functions within the class name. In Chapter 5, access control (implementation hiding)  was introduced. This gives the class designer a way to establish clear boundaries for determining  what the client programmer is allowed to manipulate and what is off limits. It means the internal  mechanisms of a data type’s operation are under the control and discretion of the class designer,  and it’s clear to client programmers what members they can and should pay attention to. Together, encapsulation and access control make a significant step in improving the ease of library  use. The concept of “new data type” they provide is better in some ways than the existing built-in  data types from C. The C++ compiler can now provide type-checking guarantees for that data type  and thus ensure a level of safety when that data type is being used. When it comes to safety, however, there’s a lot more the compiler can do for us than C provides. In  this and future chapters, you’ll see additional features that have been engineered into C++ that  make the bugs in your program almost leap out and grab you, sometimes before you even compile  the program, but usually in the form of compiler warnings and errors. For this reason, you will soon  get used to the unlikely-sounding scenario that a C++ program that compiles often runs right the  first time. Two of these safety issues are initialization and cleanup. A large segment of C bugs occur when the  programmer forgets to initialize or clean up a variable. This is especially true with C libraries, when  client programmers don’t know how to initialize a  struct , or even that they must. (Libraries often do  not include an initialization function, so the client programmer is forced to initialize the  struct  by  hand.) Cleanup is a special problem because C programmers are comfortable with forgetting about  variables once they are finished, so any cleaning up that may be necessary for a library’s  struct  is 
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
often missed.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern