O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

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

Item 36. Class-Specific Memory Management

If you don’t like the way standard operator new and operator delete are treating one of your class types, you don’t have to stand for it. Instead, your types can have their own operator new and operator delete customized to their needs.

Note that we can’t do anything with the new operator or the delete operator, since their behavior is fixed, but we can change which operator new and operator delete they invoke (see Placement New [35, 119]). The best way to do this is to declare member operator new and operator delete functions:

image

When we allocate an object of type Handle in a new expression, the compiler ...

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