Policy-Based Hierarchy Template Abstraction

Policy-Based Design

Utilizing parameter types as polices is a common practice in C++ library design; however a common issue encountered with utilizing the type defined by the provided polices is that it is unique (of course C++ is strongly typed). Therefore a library may provide a purely abstract interface for some concept, where the derived classes will utilize polices to provide the implementation. Additionally the policy interface can be enforced (post 0×11, pre 0×14).

Forward Declared Template Use (Pointer)

Forward Declared Template Parameter

Overview:
As with a typical circular-dependency break implemented with a forward declaration, this template-based example illustrates that the same is possible on a templated-type. Even though the declaration of MyType is used as part of the inheritance hierarchy, it is only a template type and not a base. Therefore the definition of MyType is still not required and a forward-declaration can be used. This is fairly straight forward so creating an example is relatively simple. Since the template instantiation only requires a MyType pointer, it can fulfill the requirements of the BaseType’s pointer member.

Example: