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 56. Policies

In Specializing for Type Information [52, 183], we designed a stack template that deleted any remaining elements left in the stack at the end of the stack’s lifetime if the stack’s element type was a pointer.

template <typename T> class Stack;

This is not an unreasonable policy, but it is inflexible. There may be cases where the user of our stack does not want to delete what the stack’s pointers refer to. For instance, the pointers may refer to objects that are not on the heap or that are shared with other containers. Additionally, it’s possible that a pointer refers to an array of objects, rather than a single object. If we have a stack of character pointers, this is almost certainly the case, since character pointers usually ...

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