O'Reilly logo
  • First Last thinks this is interesting:

template <class T>
struct OpNewCreator
   static T* Create()
      return new T;
   ~OpNewCreator() {}

Because the destructor is protected, only derived classes can destroy policy objects, so it’s impossible for outsiders to apply delete to a pointer to a policy class. The destructor, however, is not virtual, so there is no size or speed overhead.


Cover of Modern C++ Design: Generic Programming and Design Patterns Applied


Avoiding virtual destructors to be called on base class pointer