O'Reilly logo

C++ All-In-One For Dummies®, 2nd Edition by Jeff Cogswell, John Paul Mueller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Constructors, Destructors, and Exceptions

In This Chapter

  • Writing constructors

  • Using different kinds of constructors

  • Writing destructors

  • Understanding the order that takes place in construction and destruction

  • Throwing and catching exceptions

Now's the time to seriously master C++. In this chapter, we talk about three vital topics: constructors, destructors, and exceptions. Fully understanding what goes on with constructors and destructors is very important. The better you understand how constructors and destructors work, the less likely you are to write code that doesn't function the way that you expected and the more likely you are to avoid bugs.

Exceptions are important also in that they let you handle error situations — that is, you can handle problems when they do come up.

Many developers feel that constructors, destructors, and exceptions are extremely simple. In fact, many developers would doubt that these three topics could fill an entire chapter, but they can. After you read this chapter, you should have a good mastery of constructors, destructors, and exceptions.

So without further ado, you can begin to construct your reading as you destruct any old ways of programming, without exception.

Constructing and Destructing Objects

Classes are goofy little things. They like to have some say in how their instances get started. But that's okay. We're programmers, and we like to do what the computer wants us to do (as opposed to the other way around). And so the great founders of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required