46. If you provide any class-specific new, provide all of the standard forms (plain, in-place, and nothrow)

Summary

Don’t hide good news: If a class defines any overload of operator new, it should provide overloads of all three of plain, in-place, and non-throwing operator new. If you don’t, they’ll be hidden and unavailable to users of your class.

Discussion

You rarely need to provide a custom new or delete, but if you need them you usually don’t want to hide the built-in signatures.

In C++, after you define a name in a scope (e.g., in a class scope), it will hide the same name in all enclosing scopes (e.g., in base classes or enclosing namespaces), and overloading never happens across scopes. And when said name is operator new, you need ...

Get C++ Coding Standards: 101 Rules, Guidelines, and Best Practices 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.