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 
      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
      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 ...

Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.