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.
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 operatorsdelete
have a second parameter, whereasD
's do not? Do you ...
Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.