All of our examples until now have stored the policy object as a data member of the class. This is generally the preferred way of storing the policies, but it has one significant downside—a data member always has a non-zero size. Consider our smart pointer with one of the deletion policies:
template <typename T>struct DeleteByOperator { void operator()(T* p) const { delete p; }};template <typename T, typename DeletionPolicy = DeleteByOperator<T>>class SmartPtr { ..... private: T* p_; DeletionPolicy deletion_policy_;};
Note that the policy object has no data members. However, the size of the object is not zero, but one byte (we can verify that by printing the value of sizeof(DeleteByOperator<int>)). This is necessary ...