O'Reilly logo

Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions by Herb Sutter

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 36. Memory Management—Part 2

Difficulty: 6

Are you thinking about doing your own class-specific memory management, or even replacing C++'s global new and delete? First, try this problem on for size.

The following code shows classes that perform their own memory management. Point out as many memory-related errors as possible, and answer the additional questions.

  1. Consider the following code:

    class B 
    {
    public:
      virtual ~B();
      void operator delete  ( void*, size_t ) throw();
      void operator delete[]( void*, size_t ) throw();
      void f( void*, size_t ) throw();
    };
    class D : public B
    {
    public:
      void operator delete  ( void* ) throw();
      void operator delete[]( void* ) throw();
    };
    

    Why do B's operators delete have a second parameter, whereas D's do not? Do you ...

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