O'Reilly logo

Ivor Horton's Beginning Visual C++ 2013 by Ivor Horton

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 8More on Classes

  • What a destructor is and when and why you need to define it
  • How to implement a destructor
  • How to create class data members in the free store and how to delete them
  • When you must write a copy constructor for a class
  • How to make class objects work with operators such as + or *
  • How to use rvalue reference parameters to avoid unnecessary copying of class objects
  • What class templates are and how you define and use them
  • What template specializations are and how they are defined
  • What perfect forwarding is and how you can achieve it
  • How to use the standard string class for string operations

You can find the wrox.com code downloads for this chapter on the Download Code tab at www.wrox.com/go/beginningvisualc. The code is in the Chapter 8 download and individually named according to the names throughout the chapter.

CLASS DESTRUCTORS

Although this section heading relates to destructors, it’s also about dynamic memory allocation. When you allocate memory in the free store for class members, you are usually obliged to make use of a destructor, in addition to a constructor, of course. As you’ll see, dynamically allocating memory for class members will also require you to write a copy constructor.

What Is a Destructor?

A destructor is a function that destroys objects when they are no longer required or when they go out of scope. The class destructor is called automatically when an ...

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